-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
False Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeGood first issueFriendly and approachable by new contributorsFriendly and approachable by new contributorsHacktoberfestNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation
Description
Bug description
"""
The following code should lint without errors, but pylint shows:
test.py:28:6: E1101: Instance of 'A' has no 'any' member (no-member)
"""
# pylint: disable=too-few-public-methods
class A:
"""class without attributes"""
class B:
"""class with any attribute"""
def __getattr__(self, name):
return None
# uncomment to remove the error
# any = 1
def a_or_b(p) -> A | B:
"""function, which may return an instance of A or B"""
if p == "a":
return A()
return B()
x: B = a_or_b("b") # we have annotated that x is an instance of B
print(x.any) # pylint shows E1101 (no-member)
# this does not cause an error in any case
y = B()
print(y.any)Configuration
No response
Command used
pylint test.pyPylint output
************* Module test
test.py:28:6: E1101: Instance of 'A' has no 'any' member (no-member)Expected behavior
no error
Pylint version
pylint 3.2.6
astroid 3.2.4
Python 3.10.12OS / Environment
$ uname -a
Linux xxx 5.15.0-112-generic #122-Ubuntu SMP Thu May 23 07:48:21 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Additional dependencies
No response
Metadata
Metadata
Assignees
Labels
False Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeGood first issueFriendly and approachable by new contributorsFriendly and approachable by new contributorsHacktoberfestNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementation