-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
no-member on argparse result on Python 3.9 (only) #4667
Comments
I can reproduce both the false positive on Python 3.9 and that it "works" on Python 3.8. @check_messages("no-member", "c-extension-no-member")
def visit_attribute(self, node):
"""check that the accessed attribute exists
to avoid too much false positives for now, we'll consider the code as
correct if a single of the inferred nodes has the accessed attribute.
function/method, super call and metaclasses are ignored
"""
if any(
pattern.match(name)
for name in (node.attrname, node.as_string())
for pattern in self._compiled_generated_members
):
return
try:
inferred = list(node.expr.infer())
except astroid.InferenceError:
return
# list of (node, nodename) which are missing the attribute
missingattr = set()
non_opaque_inference_results = [
owner
for owner in inferred
if owner is not astroid.Uninferable
and not isinstance(owner, astroid.nodes.Unknown)
]
if (
len(non_opaque_inference_results) != len(inferred)
and self.config.ignore_on_opaque_inference
):
# There is an ambiguity in the inference. Since we can't
# make sure that we won't emit a false positive, we just stop
# whenever the inference returns an opaque inference object.
return # <-- Python 3.8 returns here With Python 3.9 in contrast, astroid.exceptions.AttributeInferenceError: 'logdir' not found on <ClassDef.Namespace> |
Interestingly, the reason why |
I have a similar situation with a Python package I maintain. This happens with Code SampleThe from cli_test_helpers import shell
result = shell("flake8")
assert result.exit_code == 0 Pylint (incorrectly) complains: test_example.py:241:15: E1101: Instance of 'Namespace' has no 'exit_code' member (no-member) Is there something I can adjust in the implementation to make it easier for Pylint to detect the members (and stop complaining for my users), or is this a Pylint shortcoming that can only be fixed inside Pylint? |
You could check if adding |
Steps to reproduce
Given a file
pylint_no_member.py
:Current behavior
On Python 3.9, Pylint raises no-member when accessing the
logdir
attribute from the argparse option--logdir
:The same command on Python 3.8 (with the same Pylint version) does not raise the issue:
Expected behavior
On Python 3.9, no-member should also not be raised.
The text was updated successfully, but these errors were encountered: