Skip to content

Fix no-member in type annotations with future import #6608

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

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ Release date: TBA
* Update ranges for ``using-constant-test`` and ``missing-parentheses-for-call-in-test``
error messages.

* Don't emit ``no-member`` inside type annotations with
``from __future__ import annotations``.

Closes #6594

..
Insert your changelog randomly, it will reduce merge conflicts
(Ie. not necessarily at the end)
Expand Down
5 changes: 5 additions & 0 deletions doc/whatsnew/2.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ Other Changes
* Update ranges for ``using-constant-test`` and ``missing-parentheses-for-call-in-test``
error messages.

* Don't emit ``no-member`` inside type annotations with
``from __future__ import annotations``.

Closes #6594

Deprecations
============

Expand Down
6 changes: 6 additions & 0 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
is_inside_abstract_class,
is_iterable,
is_mapping,
is_node_in_type_annotation_context,
is_overload_stub,
is_postponed_evaluation_enabled,
is_super,
Expand Down Expand Up @@ -1039,6 +1040,11 @@ def visit_attribute(self, node: nodes.Attribute) -> None:
):
return

if is_postponed_evaluation_enabled(node) and is_node_in_type_annotation_context(
node
):
return

try:
inferred = list(node.expr.infer())
except astroid.InferenceError:
Expand Down
10 changes: 9 additions & 1 deletion tests/functional/g/generated_members.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test the generated-members config option."""
# pylint: disable=pointless-statement, invalid-name, useless-object-inheritance
from __future__ import print_function
from __future__ import annotations
from astroid import nodes
from pylint import checkers

Expand All @@ -18,3 +18,11 @@ class Klass(object):
SESSION = Klass()
session.rollback()
SESSION.rollback()


# https://github.com/PyCQA/pylint/issues/6594
# Don't emit no-member inside type annotations
# with PEP 563 'from __future__ import annotations'
print(Klass.X) # [no-member]
var: "Klass.X"
var2: Klass.X
1 change: 1 addition & 0 deletions tests/functional/g/generated_members.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
no-member:13:6:13:18::Instance of 'Klass' has no 'spam' member:INFERENCE
no-member:26:6:26:13::Class 'Klass' has no 'X' member:INFERENCE