-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add an exception for IndexError
inside uninferable_final_decorator
#6532
Add an exception for IndexError
inside uninferable_final_decorator
#6532
Conversation
3f9553b
to
1b6ba12
Compare
Pull Request Test Coverage Report for Build 2286792493
π - Coveralls |
1b6ba12
to
2b33cf5
Compare
2b33cf5
to
e7053b7
Compare
pylint/checkers/utils.py
Outdated
@@ -850,7 +850,7 @@ def uninferable_final_decorators( | |||
if isinstance(decorator, nodes.Attribute): | |||
try: | |||
import_node = decorator.expr.lookup(decorator.expr.name)[1][0] | |||
except AttributeError: | |||
except (AttributeError, IndexError): |
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 should distinguish the two errors and try to handle the case where we can't do [1][0]
. I guess Daniel will have an opinion :)
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 believe the logic is simpler now with 38cbeeb & it more closely matches the nodes.Name
case beneath it in the same function.
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.
No, need to re-add the try-except since the primer test fails without it.
f644326
to
38cbeeb
Compare
pylint/checkers/utils.py
Outdated
@@ -849,9 +849,12 @@ def uninferable_final_decorators( | |||
for decorator in getattr(node, "nodes", []): | |||
if isinstance(decorator, nodes.Attribute): | |||
try: | |||
import_node = decorator.expr.lookup(decorator.expr.name)[1][0] | |||
_, import_nodes = decorator.expr.lookup(decorator.expr.name) | |||
except AttributeError: |
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.
Looking at the failed test this should be fixable with an isinstance
on decorator.expr
. I think we assume expr
to a LocalsDictNodeNG
while apparently in those regression tests it is a nodes.Attribute
. Should we try and fix that while we're at it?
In general I prefer explicitness over broader try...excepts
.
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.
decorator.expr
has no attribute loookup
(it is an instance of nodes.Attribute
). I could try adding a hasattr
instead of an isinstance
if I understood you.
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.
But normally it does right? My hunch is that this code works well for @decorator.func()
but not for @decorator.module.func()
. Apparently sometimes expr
sometimes does have lookup
so instead of using hasattr
can't we reliable determine what instance expr has and whether that instance is supposed to have lookup?
β¦r.py Co-authored-by: DaniΓ«l van Noord <13665637+DanielNoord@users.noreply.github.com>
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.
The new code is a lot easier to understand, that's great π
Thanks Pierre. I do want to address the suggestion from @DanielNoord later tonight. If we can wait that would be good. Otherwise I can follow up in another MR |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
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 on mobile so I can't really check if the coverage is correct. But the code LGTM.
Thanks @mbyrnepr2 for the extra effort you put in! I think this actually improves the status quo as well!
Thank you @DanielNoord & @Pierre-Sassoulas for your help π |
#6532) Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: DaniΓ«l van Noord <13665637+DanielNoord@users.noreply.github.com>
#6532) Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: DaniΓ«l van Noord <13665637+DanielNoord@users.noreply.github.com>
Type of Changes
Description
Refs #6531