Skip to content

Commit f6479fd

Browse files
authored
Fix no-member in type annotations with future import (#6608)
1 parent 0c37d4c commit f6479fd

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ Release date: TBA
321321
* Update ranges for ``using-constant-test`` and ``missing-parentheses-for-call-in-test``
322322
error messages.
323323

324+
* Don't emit ``no-member`` inside type annotations with
325+
``from __future__ import annotations``.
326+
327+
Closes #6594
328+
324329
..
325330
Insert your changelog randomly, it will reduce merge conflicts
326331
(Ie. not necessarily at the end)

doc/whatsnew/2.14.rst

+5
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ Other Changes
266266
* Update ranges for ``using-constant-test`` and ``missing-parentheses-for-call-in-test``
267267
error messages.
268268

269+
* Don't emit ``no-member`` inside type annotations with
270+
``from __future__ import annotations``.
271+
272+
Closes #6594
273+
269274
Deprecations
270275
============
271276

pylint/checkers/typecheck.py

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
is_inside_abstract_class,
3535
is_iterable,
3636
is_mapping,
37+
is_node_in_type_annotation_context,
3738
is_overload_stub,
3839
is_postponed_evaluation_enabled,
3940
is_super,
@@ -1039,6 +1040,11 @@ def visit_attribute(self, node: nodes.Attribute) -> None:
10391040
):
10401041
return
10411042

1043+
if is_postponed_evaluation_enabled(node) and is_node_in_type_annotation_context(
1044+
node
1045+
):
1046+
return
1047+
10421048
try:
10431049
inferred = list(node.expr.infer())
10441050
except astroid.InferenceError:

tests/functional/g/generated_members.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Test the generated-members config option."""
22
# pylint: disable=pointless-statement, invalid-name, useless-object-inheritance
3-
from __future__ import print_function
3+
from __future__ import annotations
44
from astroid import nodes
55
from pylint import checkers
66

@@ -18,3 +18,11 @@ class Klass(object):
1818
SESSION = Klass()
1919
session.rollback()
2020
SESSION.rollback()
21+
22+
23+
# https://github.com/PyCQA/pylint/issues/6594
24+
# Don't emit no-member inside type annotations
25+
# with PEP 563 'from __future__ import annotations'
26+
print(Klass.X) # [no-member]
27+
var: "Klass.X"
28+
var2: Klass.X
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
no-member:13:6:13:18::Instance of 'Klass' has no 'spam' member:INFERENCE
2+
no-member:26:6:26:13::Class 'Klass' has no 'X' member:INFERENCE

0 commit comments

Comments
 (0)