-
-
Notifications
You must be signed in to change notification settings - Fork 298
Fix false positive no-member in except * handler #2786
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2786 +/- ##
=======================================
Coverage 93.26% 93.26%
=======================================
Files 91 91
Lines 11010 11017 +7
=======================================
+ Hits 10268 10275 +7
Misses 742 742
Flags with carried forward coverage won't be shown. Click here to find out more.
π New features to boost your workflow:
|
astroid/protocols.py
Outdated
|
||
if isinstance(self.parent, node_classes.TryStar): | ||
# except * handler has assigned ExceptionGroup | ||
eg = nodes.ClassDef( |
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 wondering if we can just get this from builtins
and infer it from there? Why do we need to create the ClassDef
ourselves?
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 will try that.
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.
OK ExceptionGroup
constructed and infered from builtins
module...
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.
Thank you for the merge request. Are pylint and Ruff disagreeing about next ? It seems making pylint happy makes Ruff sad. Maybe there's another way to make pylint happy, I'm on mobile so I was not able to check the pipeline for the commit where pylint is sad.
The issue is following code: eg = list(
node_classes.unpack_infer(
extract_node(
"""
from builtins import ExceptionGroup
ExceptionGroup
"""
)
)
)[0] ruff does not like list with zero index, it prefers eg = next(
node_classes.unpack_infer(
extract_node(
"""
from builtins import ExceptionGroup
ExceptionGroup
"""
)
)
) without handled If I understand code correctly, it is guaranteed that at least one item is returned by EDIT: Or we can add assertion: try:
...
except StopIteration:
assert False, "Should not happen" |
Let's noqa pylint |
Type of Changes
Description
This PR allows astroid to understand that
except *
producesExceptionGroup
instead of specified exception.Note
This PR is mainly interested in
ExceptionGroup.exceptions
attribute. Other attributes/methods are left for future improvements.Refs pylint-dev/pylint#9056