Skip to content

Commit a2df2f0

Browse files
committed
Fix dis.dis without compiler feature
1 parent 8673169 commit a2df2f0

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ssl-vendor = ["ssl", "rustpython-stdlib/ssl-vendor"]
105105
[dependencies]
106106
rustpython-compiler = { workspace = true }
107107
rustpython-pylib = { workspace = true, optional = true }
108-
rustpython-stdlib = { workspace = true, optional = true }
108+
rustpython-stdlib = { workspace = true, optional = true, features = ["compiler"] }
109109
rustpython-vm = { workspace = true, features = ["compiler"] }
110110
rustpython-parser = { workspace = true }
111111

stdlib/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ edition = "2021"
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

1212
[features]
13+
default = ["compiler"]
14+
compiler = ["rustpython-vm/compiler"]
1315
threading = ["rustpython-common/threading", "rustpython-vm/threading"]
1416
zlib = ["libz-sys", "flate2/zlib"]
1517
bz2 = ["bzip2"]

stdlib/src/dis.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@ mod decl {
55
use crate::vm::{
66
builtins::{PyCode, PyDictRef, PyStrRef},
77
bytecode::CodeFlags,
8-
compiler, PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine,
8+
PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine,
99
};
1010

1111
#[pyfunction]
1212
fn dis(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
1313
let co = if let Ok(co) = obj.get_attr("__code__", vm) {
1414
// Method or function:
1515
PyRef::try_from_object(vm, co)?
16-
} else if let Ok(co_str) = PyStrRef::try_from_object(vm, obj.clone()) {
17-
// String:
18-
vm.compile(co_str.as_str(), compiler::Mode::Exec, "<dis>".to_owned())
19-
.map_err(|err| vm.new_syntax_error(&err, Some(co_str.as_str())))?
16+
} else if let Ok(_co_str) = PyStrRef::try_from_object(vm, obj.clone()) {
17+
#[cfg(not(feature = "compiler"))]
18+
return Err(vm.new_runtime_error(
19+
"dis.dis() with str argument requires `compiler` feature".to_owned(),
20+
));
21+
#[cfg(feature = "compiler")]
22+
vm.compile(
23+
_co_str.as_str(),
24+
crate::vm::compiler::Mode::Exec,
25+
"<dis>".to_owned(),
26+
)
27+
.map_err(|err| vm.new_syntax_error(&err, Some(_co_str.as_str())))?
2028
} else {
2129
PyRef::try_from_object(vm, obj)?
2230
};

0 commit comments

Comments
 (0)