Fix panic in code.replace() with non-interned strings - #8471
Conversation
code.replace() called as_interned_str().unwrap() on its string arguments, which panics when the caller passes a string that has not been interned. modulefinder's replace_paths_in_code() builds a fresh co_filename, so any use of ModuleFinder(replace_paths=...) aborted the interpreter. Intern the incoming strings instead, and raise TypeError rather than panicking when a non-string appears in co_names/co_varnames/ co_cellvars/co_freevars. Unskips test_modulefinder.test_replace_paths.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesCode metadata validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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: [x] lib: cpython/Lib/modulefinder.py dependencies:
dependent tests: (2 tests)
Legend:
|
youknowone
left a comment
There was a problem hiding this comment.
Ah, this makes sense. Obviously replace can introduce new strings. Thanks!
code.replace() called as_interned_str().unwrap() on its string arguments, which panics when the caller passes a string that has not been interned. modulefinder's replace_paths_in_code() builds a fresh co_filename, so any use of ModuleFinder(replace_paths=...) aborted the interpreter. Intern the incoming strings instead, and raise TypeError rather than panicking when a non-string appears in co_names/co_varnames/ co_cellvars/co_freevars. Unskips test_modulefinder.test_replace_paths. Co-authored-by: Pablo Garcia <pablito@MacBook-Neo-de-Pablo.local>
code.replace()calledas_interned_str().unwrap()on its string arguments, which panics when the caller passes a string that has not been interned.modulefinder.ModuleFinder(replace_paths=...)hits this:replace_paths_in_code()builds a freshco_filenameand passes it toco.replace(), aborting the interpreter. This was the last remaining skip intest_modulefinder, part of #3846.This interns the incoming strings instead, and raises
TypeErrorinstead of panicking when a non-string appears inco_names/co_varnames/co_cellvars/co_freevars.test_modulefinder.test_replace_pathsis unskipped.test_modulefinder,test_code,test_dis,test_funcattrs,test_sys_settraceall pass.Summary by CodeRabbit
TypeErrorinstead of causing failures during conversion.