-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Classmethods on typing.NamedTuple's don't recognize class attributes (no-member) #2688
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
Comments
Hrm, I think the import typing
class Spamalot(typing.NamedTuple):
name: str
EGGS = 1
def info(self):
print(self.EGGS)
print(Spamalot.EGGS) # E1101: Class 'Spamalot' has no 'EGGS' member (no-member)
Spamalot("frank").info() |
@nicktimko I think this bug comes from our lossy understanding of
Next the inference engine should know what attributes this class has. Let me know if this makes sense, happy to help with a review or more indications on how to fix this. |
Hello, Adding to the problem: I have the same result in non-class methods: import enum, typing
class TestNamedTuple(typing.NamedTuple):
member : str
class TestEnum(enum.Enum):
value : TestNamedTuple
TEST_VALUE = TestNamedTuple("test")
def test_method(self):
return self.value.member
This behavior is observed with both Using Python 3.7.2 on Windows 10, same results with Python 3.7.3 in the WSL.
|
possibly related: the same from typing import NamedTuple
class Test(NamedTuple):
a: int
b: str
def foo(self):
return self._asdict() # E1101: Instance of 'Test' has no '_asdict' member (no-member)
|
This issue has been fixed somewhere along! |
While the original example no longer emits |
Opened #7891 |
Class attributes on
typing.NamedTuple
s don't seem to be picked up, so pylint thinks they're missing and throws ano-member
error. Sounds related to #1628 which was about methods on them...if you want to point me at some stuff, I could take a look at trying to tweak it. I'm still kinda lost in the pylint/astroid code, so not super productive yet...Steps to reproduce
Current behavior
Expected behavior
No pylint errors
pylint --version output
The text was updated successfully, but these errors were encountered: