Implement more ast features by youknowone · Pull Request #6986 · RustPython/RustPython
🏁 Script executed:
cd crates/vm && wc -l src/frame.rs
Repository: RustPython/RustPython
Length of output: 82
🏁 Script executed:
cd crates/vm && sed -n '1209,1234p' src/frame.rs
Repository: RustPython/RustPython
Length of output: 1413
🏁 Script executed:
cd crates/vm && sed -n '2151,2169p' src/frame.rs
Repository: RustPython/RustPython
Length of output: 927
🏁 Script executed:
cd crates/vm && rg "get_attr" --type rust -B2 -A2 | head -50
Repository: RustPython/RustPython
Length of output: 2773
🏁 Script executed:
cd crates/vm && rg "module_type" --type rust | head -20
Repository: RustPython/RustPython
Length of output: 680
🏁 Script executed:
cd crates/vm && rg "\.class\(\)" --type rust -B1 -A1 | head -30
Repository: RustPython/RustPython
Length of output: 1642
🏁 Script executed:
cd crates/vm && rg "builtins.*module" --type rust -B2 -A2 | head -40
Repository: RustPython/RustPython
Length of output: 2296
🏁 Script executed:
cd crates/vm && rg "get_item" src/frame.rs -B3 -A3 | head -60
Repository: RustPython/RustPython
Length of output: 2874
🏁 Script executed:
cd crates/vm && grep -n "attribute_error\|key_error" src/frame.rs | head -20
Repository: RustPython/RustPython
Length of output: 1161
🏁 Script executed:
cd crates && find . -name "*.rs" -type f -exec grep -l "PyModule" {} \; | grep -E "builtins|module" | head -5
Repository: RustPython/RustPython
Length of output: 205
🏁 Script executed:
cd crates/vm && sed -n '1,100p' src/builtins/module.rs
Repository: RustPython/RustPython
Length of output: 3283
🏁 Script executed:
cd crates/vm && rg "__getitem__" src/builtins/module.rs -B3 -A5
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
cd crates/vm && rg "get_item\|get_attr" src/builtins/module.rs -B2 -A2 | head -40
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
cd crates/vm && sed -n '100,300p' src/builtins/module.rs
Repository: RustPython/RustPython
Length of output: 7033
🏁 Script executed:
cd crates/vm && rg "GetAttr\|Initializer" src/builtins/module.rs -B2 -A8 | head -50
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
cd crates/vm && python3 << 'EOF' import sys # In Python, modules don't support __getitem__ # They support __getattr__ via attribute access # Check the behavior: mod = sys try: mod["path"] # This will fail except TypeError as e: print(f"__getitem__ on module raises: {type(e).__name__}: {e}") try: getattr(mod, "path") # This works print("__getattr__ on module works") except AttributeError as e: print(f"__getattr__ raises: {e}") try: getattr(mod, "nonexistent_attr") except AttributeError as e: print(f"__getattr__ for missing attr raises AttributeError: {type(e).__name__}") EOF
Repository: RustPython/RustPython
Length of output: 237
🏁 Script executed:
cd crates/vm && rg "fn get_item" src/builtins/*.rs -A5 | head -60
Repository: RustPython/RustPython
Length of output: 1137
🏁 Script executed:
cd crates/vm && rg "object.get_item\|obj.get_item" src/ --type rust -B2 -A3 | head -50
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
cd crates && find . -name "*.rs" -type f -exec grep -l "fn get_item" {} \; | head -10
Repository: RustPython/RustPython
Length of output: 205
🏁 Script executed:
cd crates/vm && sed -n '1,100p' src/protocol/object.rs
Repository: RustPython/RustPython
Length of output: 3552
🏁 Script executed:
cd crates/vm && rg "pub fn get_item" src/protocol/object.rs -A10 | head -40
Repository: RustPython/RustPython
Length of output: 530
🏁 Script executed:
cd crates/vm && grep -n "get_item" src/protocol/object.rs | head -20
Repository: RustPython/RustPython
Length of output: 294
🏁 Script executed:
cd crates/vm && sed -n '686,720p' src/protocol/object.rs
Repository: RustPython/RustPython
Length of output: 1504
🏁 Script executed:
cd crates/vm && rg "try_mapping\|try_sequence" src/protocol/object.rs -B2 -A8 | head -50
Repository: RustPython/RustPython
Length of output: 47
🏁 Script executed:
cd crates/vm && rg "\.class\(\)\.is\(vm\.ctx\.types\." src/ --type rust -B1 -A1 | head -40
Repository: RustPython/RustPython
Length of output: 2395
🏁 Script executed:
cd crates/vm && rg "get_attr.*vm\)" src/frame.rs -B2 -A2 | head -30
Repository: RustPython/RustPython
Length of output: 1579
🏁 Script executed:
cd crates/vm && cargo clippy --lib 2>&1 | grep -A5 "frame.rs" | head -30
Repository: RustPython/RustPython
Length of output: 151
🏁 Script executed:
cd crates/vm && cargo fmt --check -- src/frame.rs 2>&1 | head -20
Repository: RustPython/RustPython
Length of output: 604
Handle module-style __builtins__ lookup to avoid TypeError.
When __builtins__ is a module (the common case), calling get_item raises TypeError, which is not caught by the code expecting KeyError. This breaks LOAD_BUILD_CLASS and global/builtin name resolution.
For modules, use get_attr instead (which raises AttributeError on missing attributes, translatable to NameError). Keep get_item for dict/mapping objects.
This applies to both the LOAD_BUILD_CLASS instruction (lines 1209-1234) and the slow-path name lookup (lines 2151-2169).