Fix RuntimeError caused by analyzing live objects with __getattribute__ or descriptors#2687
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2687 +/- ##
=======================================
Coverage 93.19% 93.19%
=======================================
Files 93 93
Lines 11066 11067 +1
=======================================
+ Hits 10313 10314 +1
Misses 753 753
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
DanielNoord
left a comment
There was a problem hiding this comment.
Is there a chance we can add a test for this? Or is that too difficult?
| """Create a list of nodes to function as the elements of a new node.""" | ||
| elements: list[NodeNG] = [] | ||
| for element in value: | ||
| # NOTE: avoid accessing any attributes of element in the loop. |
There was a problem hiding this comment.
Let's remove this comment and the one below. If the implementation of const_factory ever changes this is outdated. Imo, comments should be at the offending code (which you already did 😄)
There was a problem hiding this comment.
I'm not sure I understand.
The problem happens in the loop, so possibly it could occur directly in _create_basic_elements() without need for const_factory() to cause it.
I added the extra comments because the value is dangerous for the whole loop body (including const_factory()), until the value might be identified as const type.
DanielNoord
left a comment
There was a problem hiding this comment.
@jacobtylerwalls Anything to add?
|
The backport to To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-maintenance/3.3.x maintenance/3.3.x
# Navigate to the new working tree
cd .worktrees/backport-maintenance/3.3.x
# Create a new branch
git switch --create backport-2687-to-maintenance/3.3.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 71dc6b2412f95e0ad01cefdd6ee0d8e9ea551376
# Push it to GitHub
git push --set-upstream origin backport-2687-to-maintenance/3.3.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-maintenance/3.3.xThen, create a pull request where the |
…e__` or descriptors (pylint-dev#2687) Avoid some attribute accesses in const_factory (cherry picked from commit 71dc6b2)
Type of Changes
Description
During checking, lazy module objects may get loaded during analysis of
sys.modules, causing a crash. (In general, when an object executes code from an attribute access, making its containing collection change size.)Avoid some attribute accesses in
const_factory()to avoid executing__getattribute__code.Closes #2686
Closes pylint-dev/pylint#8589