Skip to content

Commit

Permalink
Require Python 3.7.2 (#1542)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored May 10, 2022
1 parent 1ae8c3d commit 301b559
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 179 deletions.
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 @@ -6,9 +6,7 @@
import sys
from pathlib import Path

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
18 changes: 11 additions & 7 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
import sys
import typing
import warnings
from typing import TYPE_CHECKING, Dict, List, Optional, Set, TypeVar, Union, overload
from typing import (
TYPE_CHECKING,
Dict,
List,
NoReturn,
Optional,
Set,
TypeVar,
Union,
overload,
)

from astroid import bases
from astroid import decorators as decorators_mod
Expand Down Expand Up @@ -44,12 +54,6 @@
from astroid.nodes.scoped_nodes.utils import builtin_lookup
from astroid.nodes.utils import Position

if sys.version_info >= (3, 6, 2):
from typing import NoReturn
else:
from typing_extensions import NoReturn


if sys.version_info >= (3, 8):
from functools import cached_property
from typing import Literal
Expand Down
Loading

0 comments on commit 301b559

Please sign in to comment.