From fb8fc98984850819babed1ca15e0f873f52e66ab Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Wed, 23 Dec 2020 16:05:43 +0300 Subject: [PATCH 1/2] Make postponed annotations enabled by default for 3.10+ --- CONTRIBUTORS.txt | 2 ++ pylint/checkers/utils.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index e0e3d68576..19f4842c18 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -433,3 +433,5 @@ contributors: * Raphael Gaschignard: contributor * Sorin Sbarnea: contributor + +* Batuhan Taskaya: contributor diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 23836f9097..ed2c2a5a98 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -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 @@ -1264,6 +1265,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 sys.version_info[:2] >= (3, 10): + return True + module = node.root() return "annotations" in module.future_imports From 10db2e4018a88c418d0e39ff7824414dea4af8c3 Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Mon, 28 Dec 2020 12:42:53 +0300 Subject: [PATCH 2/2] Add changelog entry --- ChangeLog | 4 ++++ pylint/checkers/utils.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f47d68b0c2..9b3ba0f01f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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? =========================== diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index ed2c2a5a98..6c707e10f9 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -213,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): @@ -1265,7 +1266,7 @@ 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 sys.version_info[:2] >= (3, 10): + if PY310_PLUS: return True module = node.root()