-
-
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
Fix abstract-class-instantiated
false positive for __new__
method.
#8006
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8006 +/- ##
=======================================
Coverage 95.51% 95.52%
=======================================
Files 176 176
Lines 18541 18557 +16
=======================================
+ Hits 17710 17726 +16
Misses 831 831
|
This comment has been minimized.
This comment has been minimized.
45e7296
to
87fb10c
Compare
Blocked by codecov issue |
87fb10c
to
aa898b4
Compare
This comment has been minimized.
This comment has been minimized.
primer output is exactly what we'd expect here |
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 for fixing the coverage and test!
if "__new__" not in node.locals: | ||
return False | ||
|
||
new = next(node.igetattr("__new__")) |
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.
This should probably be done in a try...except
. Or with safe_infer
.
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.
try:
new = next(node.igetattr("__new__"))
except astroid.InferenceError:
return False
is the closest I see to other repo code using igetattr. However, I can't think of a single example where we'd actually raise InferenceError
since new is a dunder for pretty much any class. Do you have a suggestion? I can remove the try/except or ignore coverage for this line just for precaution.
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.
Hmm.. @Pierre-Sassoulas what do you want? Non-covered code? Or code that is known to raise a certain exception that we just don't know the edge case for yet?
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 go with uncovered code catching the inference errors, it's safer imo.
@@ -467,8 +496,16 @@ def _check_inferred_class_is_abstract( | |||
return | |||
|
|||
if metaclass.qname() in ABC_METACLASSES: |
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 make L498 a if not
and then return. There is no need for this indentation here.
import weakref | ||
from lala import Bala | ||
import pandas as pd |
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 test as we don't install pandas
.
"""book.""" | ||
|
||
|
||
bad = GoodithComplexNew() |
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.
What about:
def __new__(self):
cls = super().__new__()
return cls
def __new__(self):
cls = super().__new__()
return "1"
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.
as long as the class has abstract methods, yes msg will be emitted. will add them as test cases
aa898b4
to
64d81ad
Compare
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.
Could you take a look at the coverage? For the first one the pragma needs to be on the line two below.
64d81ad
to
1dac582
Compare
This comment has been minimized.
This comment has been minimized.
self.add_message( | ||
"abstract-class-instantiated", args=(inferred.name,), node=node | ||
) | ||
if metaclass.qname() not in ABC_METACLASSES: |
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.
Can you add a test for this?
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.
Turns out I can't come up with a single class example where we would land in this code, so going to remove this check. The previous if-checks above this handle the edge cases.
1dac582
to
bf04d87
Compare
This comment has been minimized.
This comment has been minimized.
hm need to see what's up with that new primer output |
bf04d87
to
e600117
Compare
I'm still stumped by
I tried to reproduce it locally bit that msg doesn't get raised. Maybe a maintainer has a better idea? |
Have you checked wether |
It does ... while I can see |
I don't understand this comment. If |
Maybe I'm misunderstanding the purpose of the msg Anyway, if I'm wrong, then this PR should be able to be merged, I think everything asked is complete? |
But isn't one of the abstract methods of |
This PR needs take over because because it has been open 8 weeks with no activity. |
Closing this as it seems to have stalled. |
Type of Changes
Description
Closes #3060