FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Align symtable flag names with CPython by ShaharNaveh · Pull Request #8184 · RustPython/RustPython · GitHub

Repository navigation

3 changes: 0 additions & 3 deletions Lib/test/test_symtable.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ def test_globals(self):
self.assertTrue(self.top.lookup("some_non_assigned_global_var").is_global())
self.assertTrue(self.top.lookup("some_assigned_global_var").is_global())

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_nonlocal(self):
self.assertFalse(self.spam.lookup("some_var").is_nonlocal())
self.assertTrue(self.other_internal.lookup("some_var").is_nonlocal())
Expand All @@ -288,7 +287,6 @@ def test_local(self):
def test_free(self):
self.assertTrue(self.internal.lookup("x").is_free())

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_referenced(self):
self.assertTrue(self.internal.lookup("x").is_referenced())
self.assertTrue(self.spam.lookup("internal").is_referenced())
Expand Down Expand Up @@ -358,7 +356,6 @@ def test_annotated(self):
' x: int',
'test', 'exec')

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_imported(self):
self.assertTrue(self.top.lookup("sys").is_imported())

Expand Down
24 changes: 12 additions & 12 deletions crates/codegen/src/compile.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ impl<'warnings> Compiler<'warnings> {
self.symbol_table_stack
.first()
.and_then(|table| table.symbols.get(name))
.is_some_and(|sym| sym.flags.contains(SymbolFlags::IMPORTED))
.is_some_and(|sym| sym.flags.contains(SymbolFlags::DEF_IMPORT))
}

/// Get the cell-relative index of a free variable.
Expand Down Expand Up @@ -1667,10 +1667,10 @@ impl<'warnings> Compiler<'warnings> {
}

// Check if __class__ is available as a cell/free variable
// The scope must be Free (from enclosing class) or have FREE_CLASS flag
// The scope must be Free (from enclosing class) or have DEF_FREE_CLASS flag
if let Some(symbol) = table.lookup("__class__") {
if symbol.scope != SymbolScope::Free
&& !symbol.flags.contains(SymbolFlags::FREE_CLASS)
&& !symbol.flags.contains(SymbolFlags::DEF_FREE_CLASS)
{
return None;
}
Expand Down Expand Up @@ -1788,7 +1788,7 @@ impl<'warnings> Compiler<'warnings> {
.symbols
.iter()
.filter(|(_, s)| {
s.scope == SymbolScope::Cell || s.flags.contains(SymbolFlags::COMP_CELL)
s.scope == SymbolScope::Cell || s.flags.contains(SymbolFlags::DEF_COMP_CELL)
})
.map(|(name, _)| name.clone())
.collect();
Expand Down Expand Up @@ -1836,9 +1836,9 @@ impl<'warnings> Compiler<'warnings> {
.filter(|(_, s)| {
s.scope == SymbolScope::Free
|| (scope_type != CompilerScope::Class
&& s.flags.contains(SymbolFlags::FREE_CLASS))
&& s.flags.contains(SymbolFlags::DEF_FREE_CLASS))
|| (scope_type == CompilerScope::Class
&& s.flags.contains(SymbolFlags::FREE_CLASS)
&& s.flags.contains(SymbolFlags::DEF_FREE_CLASS)
&& self.has_enclosing_non_module_code_scope())
})
.filter(|(name, symbol)| {
Expand Down Expand Up @@ -3048,7 +3048,7 @@ impl<'warnings> Compiler<'warnings> {
.rev()
.find(|table| table.typ == CompilerScope::Class)
.and_then(|table| table.lookup(name.as_ref()))
.is_some_and(|symbol| symbol.flags.contains(SymbolFlags::GLOBAL));
.is_some_and(|symbol| symbol.flags.contains(SymbolFlags::DEF_GLOBAL));

(
symbol.map(|s| s.scope),
Expand Down Expand Up @@ -5513,7 +5513,7 @@ impl<'warnings> Compiler<'warnings> {
Some(symbol) => match symbol.scope {
SymbolScope::Cell => Ok(SymbolScope::Cell),
SymbolScope::Free => Ok(SymbolScope::Free),
_ if symbol.flags.contains(SymbolFlags::FREE_CLASS) => Ok(SymbolScope::Free),
_ if symbol.flags.contains(SymbolFlags::DEF_FREE_CLASS) => Ok(SymbolScope::Free),
_ => Err(CodegenErrorType::SyntaxError(format!(
"get_ref_type: invalid scope for '{name}'"
))),
Expand Down Expand Up @@ -10804,13 +10804,13 @@ impl<'warnings> Compiler<'warnings> {
let mut pushed_locals: Vec<String> = Vec::new();
let mut fast_hidden_locals: Vec<String> = Vec::new();
for (name, sym) in &comp_table.symbols {
if sym.flags.contains(SymbolFlags::PARAMETER) {
if sym.flags.contains(SymbolFlags::DEF_PARAM) {
continue; // skip .0
}
let is_local = sym
.flags
.intersects(SymbolFlags::ASSIGNED | SymbolFlags::ITER)
&& !sym.flags.contains(SymbolFlags::NONLOCAL);
.intersects(SymbolFlags::DEF_LOCAL | SymbolFlags::ITER)
&& !sym.flags.contains(SymbolFlags::DEF_NONLOCAL);
if is_local {
pushed_locals.push(name.clone());
}
Expand All @@ -10824,7 +10824,7 @@ impl<'warnings> Compiler<'warnings> {
// module/class scopes, also enable temporary fast locals for
// comprehension-bound names only.
for (name, comp_sym) in &comp_table.symbols {
if comp_sym.flags.contains(SymbolFlags::PARAMETER) {
if comp_sym.flags.contains(SymbolFlags::DEF_PARAM) {
continue; // skip .0
}
let comp_scope = comp_sym.scope;
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL