Always load __debug__ as a const.

This commit is contained in:
DimitrisJim
2023-02-26 09:23:07 +02:00
parent 547d752df5
commit 8405693325
2 changed files with 8 additions and 2 deletions

View File

@@ -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')

View File

@@ -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);