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

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented May 13, 2022

Description

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

With PEP 563, annotations are stored as strings and thus not executed. This can cause false-positives if attributes are used which don't exist in the version used to run pylint.

# pylint: disable=missing-docstring,unused-argument
from __future__ import annotations

import ast
import sys

if sys.version_info >= (3, 10):
    def func(node: ast.Match) -> None:  # no-member
        ...

If Python 3.8 is used, pylint would currently emit a no-member error for ast.Match (which was added in 3.10).
By excluding type annotations with from __future__ import annotations, the behavior will be similar to normal string annotations (which don't emit an error).

def func(node: "ast.Match") -> None:
    ...

Closes #6594

@cdce8p cdce8p added the False Positive 🦟 A message is emitted but nothing is wrong with the code label May 13, 2022
@cdce8p cdce8p added this to the 2.14.0 milestone May 13, 2022
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2320780359

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.0006%) to 95.347%

Totals Coverage Status
Change from base Build 2320650537: 0.0006%
Covered Lines: 16045
Relevant Lines: 16828

💛 - Coveralls

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cdce8p cdce8p merged commit f6479fd into main May 13, 2022
@cdce8p cdce8p deleted the no-member-annotations branch May 13, 2022 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no-member error in annotations
3 participants