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

Require Python 3.7.2 #1542

Merged
merged 5 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
python-version: [3.7, 3.8, 3.9, "3.10"]
outputs:
python-key: ${{ steps.generate-python-key.outputs.key }}
steps:
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
python-version: [3.7, 3.8, 3.9, "3.10"]
steps:
- name: Set temp directory
run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
Expand Down Expand Up @@ -282,7 +282,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["pypy-3.6", "pypy-3.7", "pypy-3.8"]
python-version: ["pypy-3.7", "pypy-3.8"]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:
hooks:
- id: pyupgrade
exclude: tests/testdata
args: [--py36-plus]
args: [--py37-plus]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
Expand Down
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ What's New in astroid 2.12.0?
=============================
Release date: TBA

* ``astroid`` now requires Python 3.7.2 to run.

* Fix ``re`` brain on Python ``3.11``. The flags now come from ``re._compile``.

* Build ``nodes.Module`` for frozen modules which have location information in their
Expand Down
31 changes: 14 additions & 17 deletions astroid/brain/brain_crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@

from astroid.brain.helpers import register_module_extender
from astroid.builder import parse
from astroid.const import PY37_PLUS
from astroid.manager import AstroidManager

if PY37_PLUS:
# Since Python 3.7 Hashing Methods are added
# dynamically to globals()

def _re_transform():
return parse(
"""
from collections import namedtuple
_Method = namedtuple('_Method', 'name ident salt_chars total_size')

METHOD_SHA512 = _Method('SHA512', '6', 16, 106)
METHOD_SHA256 = _Method('SHA256', '5', 16, 63)
METHOD_BLOWFISH = _Method('BLOWFISH', 2, 'b', 22)
METHOD_MD5 = _Method('MD5', '1', 8, 34)
METHOD_CRYPT = _Method('CRYPT', None, 2, 13)
def _re_transform():
return parse(
"""
)
from collections import namedtuple
_Method = namedtuple('_Method', 'name ident salt_chars total_size')

METHOD_SHA512 = _Method('SHA512', '6', 16, 106)
METHOD_SHA256 = _Method('SHA256', '5', 16, 63)
METHOD_BLOWFISH = _Method('BLOWFISH', 2, 'b', 22)
METHOD_MD5 = _Method('MD5', '1', 8, 34)
METHOD_CRYPT = _Method('CRYPT', None, 2, 13)
"""
)


register_module_extender(AstroidManager(), "crypt", _re_transform)
register_module_extender(AstroidManager(), "crypt", _re_transform)
29 changes: 14 additions & 15 deletions astroid/brain/brain_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from astroid import context, inference_tip
from astroid.builder import parse
from astroid.const import PY37_PLUS, PY39_PLUS
from astroid.const import PY39_PLUS
from astroid.exceptions import (
AstroidSyntaxError,
InferenceError,
Expand Down Expand Up @@ -449,19 +449,18 @@ def _infer_instance_from_annotation(
yield klass.instantiate_class()


if PY37_PLUS:
AstroidManager().register_transform(
ClassDef, dataclass_transform, is_decorated_with_dataclass
)
AstroidManager().register_transform(
ClassDef, dataclass_transform, is_decorated_with_dataclass
)

AstroidManager().register_transform(
Call,
inference_tip(infer_dataclass_field_call, raise_on_overwrite=True),
_looks_like_dataclass_field_call,
)
AstroidManager().register_transform(
Call,
inference_tip(infer_dataclass_field_call, raise_on_overwrite=True),
_looks_like_dataclass_field_call,
)

AstroidManager().register_transform(
Unknown,
inference_tip(infer_dataclass_attribute, raise_on_overwrite=True),
_looks_like_dataclass_attribute,
)
AstroidManager().register_transform(
Unknown,
inference_tip(infer_dataclass_attribute, raise_on_overwrite=True),
_looks_like_dataclass_attribute,
)
9 changes: 4 additions & 5 deletions astroid/brain/brain_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from astroid import context, inference_tip, nodes
from astroid.brain.helpers import register_module_extender
from astroid.builder import _extract_single_node, parse
from astroid.const import PY37_PLUS, PY39_PLUS, PY311_PLUS
from astroid.const import PY39_PLUS, PY311_PLUS
from astroid.manager import AstroidManager


Expand Down Expand Up @@ -90,7 +90,6 @@ def infer_pattern_match(
return iter([class_def])


if PY37_PLUS:
AstroidManager().register_transform(
nodes.Call, inference_tip(infer_pattern_match), _looks_like_pattern_or_match
)
AstroidManager().register_transform(
nodes.Call, inference_tip(infer_pattern_match), _looks_like_pattern_or_match
)
82 changes: 27 additions & 55 deletions astroid/brain/brain_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from astroid.brain.helpers import register_module_extender
from astroid.builder import parse
from astroid.const import PY37_PLUS, PY39_PLUS
from astroid.const import PY39_PLUS
from astroid.manager import AstroidManager


Expand All @@ -17,9 +17,7 @@ def _subprocess_transform():
self, args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None,
preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None,
universal_newlines=False, startupinfo=None, creationflags=0, restore_signals=True,
start_new_session=False, pass_fds=(), *, encoding=None, errors=None"""
if PY37_PLUS:
args += ", text=None"
start_new_session=False, pass_fds=(), *, encoding=None, errors=None, text=None"""
init = f"""
def __init__({args}):
pass"""
Expand All @@ -30,57 +28,31 @@ def __exit__(self, *args): pass
"""
py3_args = "args = []"

if PY37_PLUS:
check_output_signature = """
check_output(
args, *,
stdin=None,
stderr=None,
shell=False,
cwd=None,
encoding=None,
errors=None,
universal_newlines=False,
timeout=None,
env=None,
text=None,
restore_signals=True,
preexec_fn=None,
pass_fds=(),
input=None,
bufsize=0,
executable=None,
close_fds=False,
startupinfo=None,
creationflags=0,
start_new_session=False
):
""".strip()
else:
check_output_signature = """
check_output(
args, *,
stdin=None,
stderr=None,
shell=False,
cwd=None,
encoding=None,
errors=None,
universal_newlines=False,
timeout=None,
env=None,
restore_signals=True,
preexec_fn=None,
pass_fds=(),
input=None,
bufsize=0,
executable=None,
close_fds=False,
startupinfo=None,
creationflags=0,
start_new_session=False
):
""".strip()
check_output_signature = """
check_output(
args, *,
stdin=None,
stderr=None,
shell=False,
cwd=None,
encoding=None,
errors=None,
universal_newlines=False,
timeout=None,
env=None,
text=None,
restore_signals=True,
preexec_fn=None,
pass_fds=(),
input=None,
bufsize=0,
executable=None,
close_fds=False,
startupinfo=None,
creationflags=0,
start_new_session=False
):
""".strip()

code = textwrap.dedent(
f"""
Expand Down
37 changes: 15 additions & 22 deletions astroid/brain/brain_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from astroid import context, extract_node, inference_tip
from astroid.builder import _extract_single_node
from astroid.const import PY37_PLUS, PY38_PLUS, PY39_PLUS
from astroid.const import PY38_PLUS, PY39_PLUS
from astroid.exceptions import (
AttributeInferenceError,
InferenceError,
Expand Down Expand Up @@ -148,22 +148,16 @@ def infer_typing_attr(
except (InferenceError, StopIteration) as exc:
raise UseInferenceDefault from exc

if (
not value.qname().startswith("typing.")
or PY37_PLUS
and value.qname() in TYPING_ALIAS
):
# If typing subscript belongs to an alias
# (PY37+) handle it separately.
if not value.qname().startswith("typing.") or value.qname() in TYPING_ALIAS:
# If typing subscript belongs to an alias handle it separately.
raise UseInferenceDefault

if (
PY37_PLUS
and isinstance(value, ClassDef)
and value.qname()
in {"typing.Generic", "typing.Annotated", "typing_extensions.Annotated"}
):
# With PY37+ typing.Generic and typing.Annotated (PY39) are subscriptable
if isinstance(value, ClassDef) and value.qname() in {
"typing.Generic",
"typing.Annotated",
"typing_extensions.Annotated",
}:
# typing.Generic and typing.Annotated (PY39) are subscriptable
# through __class_getitem__. Since astroid can't easily
# infer the native methods, replace them for an easy inference tip
func_to_add = _extract_single_node(CLASS_GETITEM_TEMPLATE)
Expand Down Expand Up @@ -424,10 +418,9 @@ def infer_typing_cast(
ClassDef, inference_tip(infer_old_typedDict), _looks_like_typedDict
)

if PY37_PLUS:
AstroidManager().register_transform(
Call, inference_tip(infer_typing_alias), _looks_like_typing_alias
)
AstroidManager().register_transform(
Call, inference_tip(infer_special_alias), _looks_like_special_alias
)
AstroidManager().register_transform(
Call, inference_tip(infer_typing_alias), _looks_like_typing_alias
)
AstroidManager().register_transform(
Call, inference_tip(infer_special_alias), _looks_like_special_alias
)
2 changes: 0 additions & 2 deletions astroid/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import enum
import sys

PY36 = sys.version_info[:2] == (3, 6)
PY38 = sys.version_info[:2] == (3, 8)
PY37_PLUS = sys.version_info >= (3, 7)
PY38_PLUS = sys.version_info >= (3, 8)
PY39_PLUS = sys.version_info >= (3, 9)
PY310_PLUS = sys.version_info >= (3, 10)
Expand Down
20 changes: 2 additions & 18 deletions astroid/rebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ast
import sys
import token
import tokenize
from io import StringIO
from tokenize import TokenInfo, generate_tokens
from typing import (
Expand All @@ -29,7 +28,7 @@

from astroid import nodes
from astroid._ast import ParserModule, get_parser_module, parse_function_type_comment
from astroid.const import IS_PYPY, PY36, PY38, PY38_PLUS, PY39_PLUS, Context
from astroid.const import IS_PYPY, PY38, PY38_PLUS, PY39_PLUS, Context
from astroid.manager import AstroidManager
from astroid.nodes import NodeNG
from astroid.nodes.utils import Position
Expand Down Expand Up @@ -148,12 +147,6 @@ def _get_position_info(
keyword_tokens: Tuple[int, ...] = (token.NAME,)
if isinstance(parent, nodes.AsyncFunctionDef):
search_token = "async"
if PY36:
# In Python 3.6, the token type for 'async' was 'ASYNC'
# In Python 3.7, the type was changed to 'NAME' and 'ASYNC' removed
# Python 3.8 added it back. However, if we use it unconditionally
# we would break 3.7.
keyword_tokens = (token.NAME, token.ASYNC)
elif isinstance(parent, nodes.FunctionDef):
search_token = "def"
else:
Expand Down Expand Up @@ -200,12 +193,7 @@ def _fix_doc_node_position(self, node: NodesWithDocsType) -> None:

found_start, found_end = False, False
open_brackets = 0
skip_token: Set[int] = {token.NEWLINE, token.INDENT}
if PY36:
skip_token.update((tokenize.NL, tokenize.COMMENT))
else:
# token.NL and token.COMMENT were added in 3.7
skip_token.update((token.NL, token.COMMENT))
skip_token: Set[int] = {token.NEWLINE, token.INDENT, token.NL, token.COMMENT}

if isinstance(node, nodes.Module):
found_end = True
Expand Down Expand Up @@ -1294,10 +1282,6 @@ def _visit_functiondef(
position=self._get_position_info(node, newnode),
doc_node=self.visit(doc_ast_node, newnode),
)
if IS_PYPY and PY36 and newnode.position:
# PyPy: col_offset in Python 3.6 doesn't include 'async',
# use position.col_offset instead.
newnode.col_offset = newnode.position.col_offset
self._fix_doc_node_position(newnode)
self._global_names.pop()
return newnode
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -43,7 +42,7 @@ install_requires =
setuptools>=20.0
typed-ast>=1.4.0,<2.0;implementation_name=="cpython" and python_version<"3.8"
typing-extensions>=3.10;python_version<"3.10"
python_requires = >=3.6.2
python_requires = >=3.7.2

[options.packages.find]
include =
Expand Down
Loading