-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Update _can_assign_attr to return False for builtins.object #946
Update _can_assign_attr to return False for builtins.object #946
Conversation
681c7a9
to
da10597
Compare
80f957a
to
c6e0435
Compare
(updated for autoflake deconflicting) |
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.
Nice fix @nelfin!
It indeed fixes a lot of issues but in the case of trying to set an attribute to object
pylint
does not complain whereas it does when trying to assign an attribute not in the slots collection.
Maybe we should add such check in pylint
. @nelfin @cdce8p @Pierre-Sassoulas what do you think about it?
Closes #945 | ||
Closes PyCQA/pylint#4232 | ||
Closes PyCQA/pylint#4221 | ||
Closes PyCQA/pylint#3970 | ||
Closes PyCQA/pylint#3595 |
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.
NIce set of bug fixed! Congrats! 👍
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.
Great change ! Yes it seems like we could extend the pylint check in another MR.
Looks like a reasonable change 👍🏻 CONST = "my_constant"
def func():
domain_data = {
CONST: None,
}
domain_data[CONST] = lambda: print("Callback called")
def _inner_func():
domain_data[CONST]() # false-positve `not-callable`
_inner_func()
func() |
@cdce8p: I was able to make a simplified version of your example fail on pylint tag 2.7.4 and astroid 2.5.3 so this issue appears to be underlying. # pylint: disable=missing-docstring
data = {
'abc': None,
}
data['abc'] = lambda: print("Callback called")
data['abc']() # false-positive `not-callable`
|
FYI @cdce8p: I've opened pylint-dev/pylint#4387 to capture some repros of the issues that we've seen during the debugging of this and #927 that I haven't otherwise been able to fix |
Ref pylint-dev#945, pylint#4232, pylint#3970, pylint#3595. Various interactions had been previously noticed with the typing/collections modules and methods named prev/next on objects. This was due to inference setting these values as instance attributes on the builtin object class due to a sentinel object and an incorrectly inferred return value in the OrderedDict definition. This change updates _can_assign_attr (and the resulting delayed_assattr behaviour) to ignore attempts to assign to object() since these would fail.
c6e0435
to
96d0496
Compare
Rebased and deconflicted changelog |
Is this mergeable now @hippo91 ? |
Steps
Description
object()
does not have a__dict__
and so does not support attribute assignment.Type of Changes
Related Issue
Closes #945