-
-
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
false positive "assigning-non-slot" error for inherited descriptor when slots are used #6001
Comments
Regarding the provided example pasted above, I think this is expected Pylint behaviour due to
|
Slots are for instance attributes, not class attributes. In this example, |
Thanks for the info @jab. I certainly don't disagree with your analysis. The correct behaviour is also seen with the simpler case: class Example:
__slots__ = ('a',)
myinstance = Example()
myinstance.b = 1 # a.py:7:0: E0237: Assigning to attribute 'b' not defined in class slots (assigning-non-slot) I think it does look like a false positive in your case :D Perhaps this line can be used to fix this also: https://github.com/PyCQA/pylint/blob/main/pylint/checkers/classes/class_checker.py#L1556 |
@mbyrnepr2, your simplified example is not the same as what's going on here. In your example, you are assigning an instance attribute This issue is about pylint incorrectly flagging an class MyDescriptor:
def __get__(self, instance, owner):
return 42
def __set__(self, instance, value):
instance.a = 42
class Example:
__slots__ = ('a',)
b = MyDescriptor()
myinstance = Example()
myinstance.b = 'set a to 42' # no error on this line, as we expect
print(myinstance.a) # prints 42 |
@jab I agree with you. It's an example of correct usage vs. what you are reporting. Sorry that I didn't communicate that clearly. |
I have seen the same issue on latest PyLint version 2.13.8. Any news on when will this be fixed yet? |
It appears this case was considered and tested here and deemed to need to emit this message. But I believe this is incorrect, as slots is meant for instance attributes, not class attributes. |
Bug description
Minimized reproducer:
A real-world (non-minimized) example where pylint produces this false positive error can be found on this line: https://github.com/jab/bidict/blob/caf703e959ed4471bc391a7794411864c1d6ab9d/bidict/_orderedbase.py#L101
Configuration
No response
Command used
Pylint output
Expected behavior
No error should be flagged here.
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: