mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Always load __debug__ as a const.
This commit is contained in:
2
Lib/test/test_compile.py
vendored
2
Lib/test/test_compile.py
vendored
@@ -31,8 +31,6 @@ class TestSpecifics(unittest.TestCase):
|
||||
compile("hi\r\nstuff\r\ndef f():\n pass\r", "<test>", "exec")
|
||||
compile("this_is\rreally_old_mac\rdef f():\n pass", "<test>", "exec")
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_debug_assignment(self):
|
||||
# catch assignments to __debug__
|
||||
self.assertRaises(SyntaxError, compile, '__debug__ = 1', '?', 'single')
|
||||
|
||||
@@ -500,6 +500,14 @@ impl Compiler {
|
||||
// // TODO: is this right?
|
||||
// SymbolScope::Unknown => NameOpType::Global,
|
||||
};
|
||||
|
||||
if NameUsage::Load == usage && name == "__debug__" {
|
||||
self.emit_constant(ConstantData::Boolean {
|
||||
value: self.opts.optimize == 0,
|
||||
});
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut idx = cache
|
||||
.get_index_of(name.as_ref())
|
||||
.unwrap_or_else(|| cache.insert_full(name.into_owned()).0);
|
||||
|
||||
Reference in New Issue
Block a user