pylint
pylint copied to clipboard
false positive: `no-member` on class variable defined by metaclass
Bug description
class ApduCommandMeta(abc.ABCMeta):
def __new__(metacls, name, bases, namespace, **kwargs):
x = super().__new__(metacls, name, bases, namespace)
x._cla = namespace.get('cla', kwargs.get('cla', None))
return x
class ApduCommand(Apdu, metaclass=ApduCommandMeta):
@classmethod
def match_cla(cls, cla) -> bool:
for cla_match in cls._cla:
In that situation the access to cls._cla triggers thge following false-positive error message:
pySim/apdu/__init__.py:266:25: E1101: Class 'ApduCommand' has no '_cla' member; maybe 'cla'? (no-member)
So somehow it seems the linter doesn't appear to be aware that it must not only look at class members of the ApduCommand base class, but but also at all the class variables that any metaclasses might add?
The complete code can be found at https://gitea.osmocom.org/sim-card/pysim/src/branch/laforge/apdu_decoder
Configuration
No response
Command used
python3 -m pylint --errors-only \ 249/0/0
--disable E1102 \
--disable E0401 \
--enable W0301 \
pySim *.py
Pylint output
pySim/apdu/__init__.py:266:25: E1101: Class 'ApduCommand' has no '_cla' member; maybe 'cla'? (no-member)
Expected behavior
I would expect the linter to consider any class variables/members added by metaclasses before complaining that some variable is not a member.
Pylint version
Python 3.10.5
pylint 2.12.2
OS / Environment
Debian unstable
Additional dependencies
No response