mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fix dis.dis without compiler feature
This commit is contained in:
committed by
Jeong, YunWon
parent
8673169ee7
commit
a2df2f014b
@@ -105,7 +105,7 @@ ssl-vendor = ["ssl", "rustpython-stdlib/ssl-vendor"]
|
||||
[dependencies]
|
||||
rustpython-compiler = { workspace = true }
|
||||
rustpython-pylib = { workspace = true, optional = true }
|
||||
rustpython-stdlib = { workspace = true, optional = true }
|
||||
rustpython-stdlib = { workspace = true, optional = true, features = ["compiler"] }
|
||||
rustpython-vm = { workspace = true, features = ["compiler"] }
|
||||
rustpython-parser = { workspace = true }
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = ["compiler"]
|
||||
compiler = ["rustpython-vm/compiler"]
|
||||
threading = ["rustpython-common/threading", "rustpython-vm/threading"]
|
||||
zlib = ["libz-sys", "flate2/zlib"]
|
||||
bz2 = ["bzip2"]
|
||||
|
||||
@@ -5,7 +5,7 @@ mod decl {
|
||||
use crate::vm::{
|
||||
builtins::{PyCode, PyDictRef, PyStrRef},
|
||||
bytecode::CodeFlags,
|
||||
compiler, PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyfunction]
|
||||
@@ -13,10 +13,18 @@ mod decl {
|
||||
let co = if let Ok(co) = obj.get_attr("__code__", vm) {
|
||||
// Method or function:
|
||||
PyRef::try_from_object(vm, co)?
|
||||
} else if let Ok(co_str) = PyStrRef::try_from_object(vm, obj.clone()) {
|
||||
// String:
|
||||
vm.compile(co_str.as_str(), compiler::Mode::Exec, "<dis>".to_owned())
|
||||
.map_err(|err| vm.new_syntax_error(&err, Some(co_str.as_str())))?
|
||||
} else if let Ok(_co_str) = PyStrRef::try_from_object(vm, obj.clone()) {
|
||||
#[cfg(not(feature = "compiler"))]
|
||||
return Err(vm.new_runtime_error(
|
||||
"dis.dis() with str argument requires `compiler` feature".to_owned(),
|
||||
));
|
||||
#[cfg(feature = "compiler")]
|
||||
vm.compile(
|
||||
_co_str.as_str(),
|
||||
crate::vm::compiler::Mode::Exec,
|
||||
"<dis>".to_owned(),
|
||||
)
|
||||
.map_err(|err| vm.new_syntax_error(&err, Some(_co_str.as_str())))?
|
||||
} else {
|
||||
PyRef::try_from_object(vm, obj)?
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user