Skip to content
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

Make postponed annotations enabled by default for 3.10+ #3993

Merged
merged 2 commits into from
Dec 29, 2020
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
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,5 @@ contributors:
* Raphael Gaschignard: contributor

* Sorin Sbarnea: contributor

* Batuhan Taskaya: contributor
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Pylint's ChangeLog

* Add missing checks for deprecated functions.

* Postponed evaluation of annotations are now recognized by default if python version is above 3.10

Closes #3992


What's New in Pylint 2.6.1?
===========================
Expand Down
5 changes: 5 additions & 0 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import numbers
import re
import string
import sys
from functools import lru_cache, partial
from typing import Callable, Dict, Iterable, List, Match, Optional, Set, Tuple, Union

Expand Down Expand Up @@ -212,6 +213,7 @@
for name in methods # type: ignore
}
PYMETHODS = set(SPECIAL_METHODS_PARAMS)
PY310_PLUS = sys.version_info[:2] >= (3, 10)


class NoSuchArgumentError(Exception):
Expand Down Expand Up @@ -1264,6 +1266,9 @@ def get_node_last_lineno(node: astroid.node_classes.NodeNG) -> int:

def is_postponed_evaluation_enabled(node: astroid.node_classes.NodeNG) -> bool:
"""Check if the postponed evaluation of annotations is enabled"""
if PY310_PLUS:
return True

module = node.root()
return "annotations" in module.future_imports

Expand Down