Align symtable filename handling and global error locations with CPython#7142
Align symtable filename handling and global error locations with CPython#7142moreal wants to merge 1 commit intoRustPython:mainfrom
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] lib: cpython/Lib/collections dependencies:
dependent tests: (193 tests)
[ ] lib: cpython/Lib/hashlib.py dependencies:
dependent tests: (15 tests)
[ ] lib: cpython/Lib/hmac.py dependencies:
dependent tests: (4 tests)
[x] lib: cpython/Lib/inspect.py dependencies:
dependent tests: (44 tests)
[x] test: cpython/Lib/test/test_keywordonlyarg.py (TODO: 1) dependencies: dependent tests: (no tests depend on keywordonlyarg) [x] test: cpython/Lib/test/test_positional_only_arg.py (TODO: 5) dependencies: dependent tests: (no tests depend on positional_only_arg) [ ] lib: cpython/Lib/smtplib.py dependencies:
dependent tests: (2 tests)
[x] lib: cpython/Lib/symtable.py dependencies:
dependent tests: (1 tests)
Legend:
|
Summary
This PR removes one
@unittest.expectedFailureintest_symtableby aligning RustPython's_symtable.symtablebehavior with CPython for filename handling and symbol-table-time error location reporting.Fixed Test
test.test_symtable.SymtableTest.test_filename_correctCompatibility gap before this PR
def f(x): global x, RustPython reportedSyntaxError.offsetusing the identifier location (x) instead of the directive statement location (global ...)._symtable.symtablein RustPython acceptedfilenameasstronly, while CPython accepts filesystem-decoded path inputs.How CPython handles it
cpython/Python/symtable.c,Global_kindandNonlocal_kinduse statement location data viaLOCATION(s)for both directive recording and syntax error location (SET_ERROR_LOCATION(st->st_filename, LOCATION(s));), so offsets point to the directive statement start.cpython/Modules/symtablemodule.c,_symtable.symtabledeclaresfilename: unicode_fs_decoded, which acceptsstr | bytes | os.PathLike.How RustPython now handles it
crates/codegen/src/symboltable.rs,Stmt::GlobalandStmt::Nonlocalnow passstatement.range()to symbol registration so symtable-build-timeSyntaxError.offsetmatches CPython's statement-based location semantics.crates/vm/src/stdlib/symtable.rs,_symtable.symtablenow takesfilename: OsPathand usesto_string_lossy()before compilation.OsPathusesTryFromObjectand delegates toPathConverter::try_path, which acceptsstrandbytes(and path-like objects through__fspath__), so existingPyStrRef-stylestrbehavior is preserved while adding CPython-compatible filename inputs.Behavioral outcome
SyntaxError.filename,SyntaxError.lineno, andSyntaxError.offsetnow match CPython for both parse-time and symtable-build-time failures intest_filename_correct.symtable.symtable("pass", b"spam", "exec")is now accepted, while invalid containers such asbytearray,memoryview, andliststill raiseTypeError.