-
-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance we can add a test for this? Or is that too difficult?
@@ -5514,6 +5514,7 @@ def _create_basic_elements( | |||
"""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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jacobtylerwalls Anything to add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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.x Then, create a pull request where the |
…e__` or descriptors (pylint-dev#2687) Avoid some attribute accesses in const_factory (cherry picked from commit 71dc6b2)
…e__` or descriptors (#2687) (#2688) Avoid some attribute accesses in const_factory (cherry picked from commit 71dc6b2) Co-authored-by: aatle <[email protected]>
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