diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-17 21:39:09 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-17 23:09:55 +0200 |
commit | 2b2845c8a7b33f604c9807e05b08267483bb823c (patch) | |
tree | 40705b5e7e92e9ce36ebf897be59b9302dbde9ea /astroid | |
parent | 8803b03416bf93ca02bd17dbb284f5fc0a7d657a (diff) | |
download | astroid-git-2b2845c8a7b33f604c9807e05b08267483bb823c.tar.gz |
Create a astroid.constants.py to avoid circular imports
And add PY3X type constants in it.
Diffstat (limited to 'astroid')
-rw-r--r-- | astroid/_ast.py | 2 | ||||
-rw-r--r-- | astroid/bases.py | 3 | ||||
-rw-r--r-- | astroid/brain/brain_collections.py | 4 | ||||
-rw-r--r-- | astroid/brain/brain_crypt.py | 4 | ||||
-rw-r--r-- | astroid/brain/brain_fstrings.py | 4 | ||||
-rw-r--r-- | astroid/brain/brain_hashlib.py | 4 | ||||
-rw-r--r-- | astroid/brain/brain_re.py | 6 | ||||
-rw-r--r-- | astroid/brain/brain_subprocess.py | 6 | ||||
-rw-r--r-- | astroid/brain/brain_type.py | 4 | ||||
-rw-r--r-- | astroid/brain/brain_typing.py | 5 | ||||
-rw-r--r-- | astroid/constants.py | 7 | ||||
-rw-r--r-- | astroid/rebuilder.py | 7 | ||||
-rw-r--r-- | astroid/scoped_nodes.py | 6 | ||||
-rw-r--r-- | astroid/test_utils.py | 2 |
14 files changed, 24 insertions, 40 deletions
diff --git a/astroid/_ast.py b/astroid/_ast.py index 8d9a8d23..8bafa799 100644 --- a/astroid/_ast.py +++ b/astroid/_ast.py @@ -5,6 +5,7 @@ from functools import partial from typing import Optional import astroid +from astroid.constants import PY38 try: import typed_ast.ast3 as _ast_py3 @@ -12,7 +13,6 @@ except ImportError: _ast_py3 = None -PY38 = sys.version_info[:2] >= (3, 8) if PY38: # On Python 3.8, typed_ast was merged back into `ast` _ast_py3 = ast diff --git a/astroid/bases.py b/astroid/bases.py index 33ffd5fc..b4c16678 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -25,10 +25,10 @@ inference utils. import builtins import collections -import sys from astroid import context as contextmod from astroid import util +from astroid.constants import PY310 from astroid.exceptions import ( AstroidTypeError, AttributeInferenceError, @@ -42,7 +42,6 @@ BUILTINS = builtins.__name__ manager = util.lazy_import("manager") MANAGER = manager.AstroidManager() -PY310 = sys.version_info >= (3, 10) # TODO: check if needs special treatment BUILTINS = "builtins" diff --git a/astroid/brain/brain_collections.py b/astroid/brain/brain_collections.py index cb3d4c20..1397f1ea 100644 --- a/astroid/brain/brain_collections.py +++ b/astroid/brain/brain_collections.py @@ -8,11 +8,9 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE -import sys import astroid - -PY39 = sys.version_info >= (3, 9) +from astroid.constants import PY39 def _collections_transform(): diff --git a/astroid/brain/brain_crypt.py b/astroid/brain/brain_crypt.py index 076c1927..b5a1cede 100644 --- a/astroid/brain/brain_crypt.py +++ b/astroid/brain/brain_crypt.py @@ -1,10 +1,8 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE -import sys import astroid - -PY37 = sys.version_info >= (3, 7) +from astroid.constants import PY37 if PY37: # Since Python 3.7 Hashing Methods are added diff --git a/astroid/brain/brain_fstrings.py b/astroid/brain/brain_fstrings.py index db0c9edb..bd98a8ba 100644 --- a/astroid/brain/brain_fstrings.py +++ b/astroid/brain/brain_fstrings.py @@ -6,9 +6,9 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE import collections.abc -import sys import astroid +from astroid.constants import PY36 def _clone_node_with_lineno(node, parent, lineno): @@ -44,7 +44,7 @@ def _transform_formatted_value(node): # pylint: disable=inconsistent-return-sta return new_node -if sys.version_info[:2] >= (3, 6): +if PY36: # TODO: this fix tries to *patch* http://bugs.python.org/issue29051 # The problem is that FormattedValue.value, which is a Name node, # has wrong line numbers, usually 1. This creates problems for pylint, diff --git a/astroid/brain/brain_hashlib.py b/astroid/brain/brain_hashlib.py index 90ba48eb..f7524847 100644 --- a/astroid/brain/brain_hashlib.py +++ b/astroid/brain/brain_hashlib.py @@ -8,11 +8,9 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE -import sys import astroid - -PY36 = sys.version_info >= (3, 6) +from astroid.constants import PY36 def _hashlib_transform(): diff --git a/astroid/brain/brain_re.py b/astroid/brain/brain_re.py index 544191b6..46acf5ca 100644 --- a/astroid/brain/brain_re.py +++ b/astroid/brain/brain_re.py @@ -1,13 +1,9 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE -import sys import astroid from astroid import MANAGER, context, inference_tip, nodes - -PY36 = sys.version_info >= (3, 6) -PY37 = sys.version_info[:2] >= (3, 7) -PY39 = sys.version_info[:2] >= (3, 9) +from astroid.constants import PY36, PY37, PY39 if PY36: # Since Python 3.6 there is the RegexFlag enum diff --git a/astroid/brain/brain_subprocess.py b/astroid/brain/brain_subprocess.py index cef1deb8..d56cb166 100644 --- a/astroid/brain/brain_subprocess.py +++ b/astroid/brain/brain_subprocess.py @@ -11,14 +11,10 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE -import sys import textwrap import astroid - -PY39 = sys.version_info >= (3, 9) -PY37 = sys.version_info >= (3, 7) -PY36 = sys.version_info >= (3, 6) +from astroid.constants import PY36, PY37, PY39 def _subprocess_transform(): diff --git a/astroid/brain/brain_type.py b/astroid/brain/brain_type.py index c7164704..2b340015 100644 --- a/astroid/brain/brain_type.py +++ b/astroid/brain/brain_type.py @@ -15,13 +15,11 @@ Doing this type[int] is allowed whereas str[int] is not. Thanks to Lukasz Langa for fruitful discussion. """ -import sys from astroid import MANAGER, extract_node, inference_tip, nodes +from astroid.constants import PY39 from astroid.exceptions import UseInferenceDefault -PY39 = sys.version_info >= (3, 9) - def _looks_like_type_subscript(node): """ diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py index 38ec26d2..18f7e637 100644 --- a/astroid/brain/brain_typing.py +++ b/astroid/brain/brain_typing.py @@ -10,21 +10,18 @@ # Copyright (c) 2021 hippo91 <guillaume.peillex@gmail.com> """Astroid hooks for typing.py support.""" -import sys import typing from functools import partial import astroid from astroid import MANAGER, context, extract_node, inference_tip, node_classes, nodes +from astroid.constants import PY37, PY39 from astroid.exceptions import ( AttributeInferenceError, InferenceError, UseInferenceDefault, ) -PY37 = sys.version_info[:2] >= (3, 7) -PY39 = sys.version_info[:2] >= (3, 9) - TYPING_NAMEDTUPLE_BASENAMES = {"NamedTuple", "typing.NamedTuple"} TYPING_TYPEVARS = {"TypeVar", "NewType"} TYPING_TYPEVARS_QUALIFIED = {"typing.TypeVar", "typing.NewType"} diff --git a/astroid/constants.py b/astroid/constants.py new file mode 100644 index 00000000..f9110dbd --- /dev/null +++ b/astroid/constants.py @@ -0,0 +1,7 @@ +import sys + +PY36 = sys.version_info >= (3, 6) +PY37 = sys.version_info >= (3, 7) +PY38 = sys.version_info >= (3, 8) +PY39 = sys.version_info >= (3, 9) +PY310 = sys.version_info >= (3, 10) diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py index d97c81b5..d71f69b9 100644 --- a/astroid/rebuilder.py +++ b/astroid/rebuilder.py @@ -29,7 +29,6 @@ order to get a single Astroid representation """ -import sys from typing import ( TYPE_CHECKING, Callable, @@ -45,6 +44,8 @@ from typing import ( overload, ) +from astroid.constants import PY37, PY38, PY39 + try: from typing import Final except ImportError: @@ -70,9 +71,7 @@ REDIRECT: Final[Dict[str, str]] = { "keyword": "Keyword", "match_case": "MatchCase", } -PY37 = sys.version_info >= (3, 7) -PY38 = sys.version_info >= (3, 8) -PY39 = sys.version_info >= (3, 9) + T_Doc = TypeVar( "T_Doc", diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index bb124d40..c3603c63 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -41,13 +41,13 @@ Lambda, GeneratorExp, DictComp and SetComp to some extent). import builtins import io import itertools -import sys from typing import List, Optional from astroid import bases from astroid import context as contextmod from astroid import decorators as decorators_mod from astroid import manager, mixins, node_classes, util +from astroid.constants import PY36, PY39 from astroid.exceptions import ( AstroidBuildingError, AstroidTypeError, @@ -60,8 +60,6 @@ from astroid.exceptions import ( ) from astroid.interpreter import dunder_lookup, objectmodel -PY39 = sys.version_info[:2] >= (3, 9) - BUILTINS = builtins.__name__ ITER_METHODS = ("__iter__", "__getitem__") EXCEPTION_BASE_CLASSES = frozenset({"Exception", "BaseException"}) @@ -1516,7 +1514,7 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda): if isinstance(frame, ClassDef): if self.name == "__new__": return "classmethod" - if sys.version_info >= (3, 6) and self.name == "__init_subclass__": + if PY36 and self.name == "__init_subclass__": return "classmethod" type_name = "method" diff --git a/astroid/test_utils.py b/astroid/test_utils.py index 2ff6eef9..974869eb 100644 --- a/astroid/test_utils.py +++ b/astroid/test_utils.py @@ -39,7 +39,7 @@ def require_version(minver=None, maxver=None): ) from exc def check_require_version(f): - current = sys.version_info[:3] + current = sys.version_info[:3] # TODO if parse(minver, "0") < current <= parse(maxver, "4"): return f |