-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixed a crash when inferring a value and using its qname on a slice #8070
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
Conversation
DanielNoord
left a comment
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 don't really like using hasattr as it is not exactly type safe. Can't we use isinstance?
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8070 +/- ##
==========================================
+ Coverage 95.43% 95.44% +0.01%
==========================================
Files 176 176
Lines 18545 18545
==========================================
+ Hits 17698 17700 +2
+ Misses 847 845 -2
|
This comment has been minimized.
This comment has been minimized.
|
Maybe we could check that it's a base.Instance ? I've seen that somewhere. Did you have something in mind ? |
Purely based on the next line ( |
|
Given our current test, it can be (and create false negative according to our tests if we don't handle those cases). What's wrong with hasattr exactly ? |
class A:
def qname(self):
return 1π There is nothing that says that |
Marc was against that here, but it also comes up regularly, see pylint-dev/astroid#1373. |
|
Hmm yeah, right thank you I understand. The problematic version would be this: class A:
def qname(self):
return "threading.lock.acquire"Because then it's a false positive for |
|
Being able to use qname on all nodes would obviously be great in order to not crash when we get unexpected nodes. (Could assignAttr qname be the name of the variable with full namespace ?) But it's a big decisions with a required astroid upgrade, maybe hasattr is a decent temporary fix. |
|
Yeah I'm not sure. |
|
Let's the how the primers react then |
|
There's a whole lot of other call to hasattr accross the codebase (qname, attrname, name). Probably something to do in another refactor merge request or after the astroid qname discussion. |
This comment has been minimized.
This comment has been minimized.
|
Hey! This does fix the first crash in the issue, but it doesn't fix the second crash in Dropping the code snippet here as well: class Foo:
def __init__(self, foo=slice(42)):
self.foo = foo
def bar():
i = Foo()
i.foo()
return 100 |
| and node.returns.name == "NoReturn" | ||
| ) | ||
| try: | ||
| return node.qname() in self._never_returning_functions |
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.
Clearly node is typed incorrectly, but oh well π
|
π€ According to the primer, this change has no effect on the checked open source code. π€π This comment was generated for commit e1a478d |
Type of Changes
Description
Closes #8067