Skip to content

Commit 1938d5e

Browse files
committed
Merge branch 'main' of https://github.com/PyCQA/astroid into orelse-lineno
2 parents cf0cfb0 + 0bf711f commit 1938d5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+486
-332
lines changed

.github/workflows/ci.yaml

+7-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
strategy:
8282
fail-fast: true
8383
matrix:
84-
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
84+
python-version: [3.7, 3.8, 3.9, "3.10"]
8585
outputs:
8686
python-key: ${{ steps.generate-python-key.outputs.key }}
8787
steps:
@@ -92,6 +92,10 @@ jobs:
9292
uses: actions/[email protected]
9393
with:
9494
python-version: ${{ matrix.python-version }}
95+
- name: Install Qt
96+
if: ${{ matrix.python-version == '3.10' }}
97+
run: |
98+
sudo apt-get install build-essential libgl1-mesa-dev
9599
- name: Generate partial Python venv restore key
96100
id: generate-python-key
97101
run: >-
@@ -229,7 +233,7 @@ jobs:
229233
strategy:
230234
fail-fast: true
231235
matrix:
232-
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
236+
python-version: [3.7, 3.8, 3.9, "3.10"]
233237
steps:
234238
- name: Set temp directory
235239
run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
@@ -278,7 +282,7 @@ jobs:
278282
strategy:
279283
fail-fast: false
280284
matrix:
281-
python-version: ["pypy-3.6", "pypy-3.7", "pypy-3.8"]
285+
python-version: ["pypy-3.7", "pypy-3.8"]
282286
steps:
283287
- name: Check out code from GitHub
284288
uses: actions/[email protected]

.github/workflows/codeql-analysis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL
46-
uses: github/codeql-action/init@v1
46+
uses: github/codeql-action/init@v2
4747
with:
4848
languages: ${{ matrix.language }}
4949
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -54,7 +54,7 @@ jobs:
5454
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5555
# If this step fails, then you should remove it and run the build manually (see below)
5656
- name: Autobuild
57-
uses: github/codeql-action/autobuild@v1
57+
uses: github/codeql-action/autobuild@v2
5858

5959
# ℹ️ Command-line programs to run using the OS shell.
6060
# 📚 https://git.io/JvXDl
@@ -68,4 +68,4 @@ jobs:
6868
# make release
6969

7070
- name: Perform CodeQL Analysis
71-
uses: github/codeql-action/analyze@v1
71+
uses: github/codeql-action/analyze@v2

.github/workflows/release-tests.yml

+3-28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on: workflow_dispatch
55
env:
66
DEFAULT_PYTHON: 3.8
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
virtualenv-15-windows-test:
1013
# Regression test added in https://github.com/PyCQA/astroid/pull/1386
@@ -31,31 +34,3 @@ jobs:
3134
. venv2\scripts\activate
3235
echo "import distutils.util # pylint: disable=unused-import" > test.py
3336
pylint test.py
34-
35-
additional-dependencies-linux-tests:
36-
name: Regression tests w/ additional dependencies (Linux)
37-
runs-on: ubuntu-latest
38-
timeout-minutes: 5
39-
steps:
40-
- name: Check out code from GitHub
41-
uses: actions/[email protected]
42-
- name: Set up Python
43-
id: python
44-
uses: actions/[email protected]
45-
with:
46-
python-version: ${{ env.DEFAULT_PYTHON }}
47-
- name: Install Qt
48-
run: |
49-
sudo apt-get install build-essential libgl1-mesa-dev
50-
- name: Create Python virtual environment
51-
run: |
52-
python -m venv venv
53-
. venv/bin/activate
54-
python -m pip install -U pip setuptools wheel
55-
pip install -U -r requirements_test.txt -r requirements_test_brain.txt
56-
pip install -e .
57-
- name: Run brain_qt tests
58-
# Regression test added in https://github.com/PyCQA/astroid/pull/1505
59-
run: |
60-
. venv/bin/activate
61-
pytest tests/unittest_brain_qt.py

.github/workflows/release.yml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
env:
99
DEFAULT_PYTHON: 3.9
1010

11+
permissions:
12+
contents: read
13+
1114
jobs:
1215
release-pypi:
1316
name: Upload release to PyPI

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ repos:
2828
exclude: tests/testdata|setup.py
2929
types: [python]
3030
- repo: https://github.com/asottile/pyupgrade
31-
rev: v2.32.0
31+
rev: v2.32.1
3232
hooks:
3333
- id: pyupgrade
3434
exclude: tests/testdata
35-
args: [--py36-plus]
35+
args: [--py37-plus]
3636
- repo: https://github.com/PyCQA/isort
3737
rev: 5.10.1
3838
hooks:
@@ -71,7 +71,7 @@ repos:
7171
]
7272
exclude: tests/testdata|conf.py
7373
- repo: https://github.com/pre-commit/mirrors-mypy
74-
rev: v0.942
74+
rev: v0.950
7575
hooks:
7676
- id: mypy
7777
name: mypy

CONTRIBUTORS.txt

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ Contributors
6767
- Peter Kolbus <[email protected]>
6868
- Omer Katz <[email protected]>
6969
- Moises Lopez <[email protected]>
70-
- Michael <[email protected]>
7170
- Keichi Takahashi <[email protected]>
7271
- Kavins Singh <[email protected]>
7372
- Karthikeyan Singaravelan <[email protected]>

ChangeLog

+41-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ What's New in astroid 2.12.0?
66
=============================
77
Release date: TBA
88

9+
* ``astroid`` now requires Python 3.7.2 to run.
10+
911
* Add ``orelse_lineno`` and ``orelse_col_offset`` attributes to ``nodes.If``.
1012

1113
* Fix ``re`` brain on Python ``3.11``. The flags now come from ``re._compile``.
@@ -15,16 +17,54 @@ Release date: TBA
1517

1618
Closes #1512
1719

20+
* Allowed ``AstroidManager.clear_cache`` to reload necessary brain plugins.
21+
1822
* Rename ``ModuleSpec`` -> ``module_type`` constructor parameter to match attribute
1923
name and improve typing. Use ``type`` instead.
2024

25+
* Infer the return value of the ``.copy()`` method on ``dict``, ``list``, ``set``,
26+
and ``frozenset``.
2127

22-
What's New in astroid 2.11.4?
28+
Closes #1403
29+
30+
What's New in astroid 2.11.6?
2331
=============================
2432
Release date: TBA
2533

34+
35+
What's New in astroid 2.11.5?
36+
=============================
37+
Release date: 2022-05-09
38+
39+
* Fix crash while obtaining ``object_type()`` of an ``Unknown`` node.
40+
41+
Refs PyCQA/pylint#6539
42+
43+
* Fix a bug where in attempting to handle the patching of ``distutils`` by ``virtualenv``,
44+
library submodules called ``distutils`` (e.g. ``numpy.distutils``) were included also.
45+
46+
Refs PyCQA/pylint#6497
47+
48+
What's New in astroid 2.11.4?
49+
=============================
50+
Release date: 2022-05-02
51+
2652
* Fix ``col_offset`` attribute for nodes involving ``with`` on ``PyPy``.
2753

54+
* Fixed a crash involving two starred expressions: one inside a comprehension,
55+
both inside a call.
56+
57+
Refs PyCQA/pylint#6372
58+
59+
* Made ``FunctionDef.implicit_parameters`` return 1 for methods by making
60+
``FunctionDef.is_bound`` return ``True``, as it does for class methods.
61+
62+
Closes PyCQA/pylint#6464
63+
64+
* Fixed a crash when ``_filter_stmts`` encounters an ``EmptyNode``.
65+
66+
Closes PyCQA/pylint#6438
67+
2868

2969
What's New in astroid 2.11.3?
3070
=============================

astroid/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import functools
3434
import tokenize
3535
from importlib import import_module
36-
from pathlib import Path
3736

3837
# isort: off
3938
# We have an isort: off on '__version__' because the packaging need to access
@@ -49,7 +48,7 @@
4948
from astroid.bases import BaseInstance, BoundMethod, Instance, UnboundMethod
5049
from astroid.brain.helpers import register_module_extender
5150
from astroid.builder import extract_node, parse
52-
from astroid.const import PY310_PLUS, Context, Del, Load, Store
51+
from astroid.const import BRAIN_MODULES_DIRECTORY, PY310_PLUS, Context, Del, Load, Store
5352
from astroid.exceptions import (
5453
AstroidBuildingError,
5554
AstroidBuildingException,
@@ -193,8 +192,6 @@
193192
tokenize._compile = functools.lru_cache()(tokenize._compile) # type: ignore[attr-defined]
194193

195194
# load brain plugins
196-
ASTROID_INSTALL_DIRECTORY = Path(__file__).parent
197-
BRAIN_MODULES_DIRECTORY = ASTROID_INSTALL_DIRECTORY / "brain"
198195
for module in BRAIN_MODULES_DIRECTORY.iterdir():
199196
if module.suffix == ".py":
200197
import_module(f"astroid.brain.{module.stem}")

astroid/brain/brain_builtin_inference.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
"""Astroid hooks for various builtins."""
66

7+
import itertools
78
from functools import partial
8-
from typing import Optional
9+
from typing import Iterator, Optional
910

1011
from astroid import arguments, helpers, inference_tip, nodes, objects, util
1112
from astroid.builder import AstroidBuilder
@@ -892,6 +893,22 @@ def _build_dict_with_elements(elements):
892893
return _build_dict_with_elements([])
893894

894895

896+
def _infer_copy_method(
897+
node: nodes.Call, context: Optional[InferenceContext] = None
898+
) -> Iterator[nodes.NodeNG]:
899+
assert isinstance(node.func, nodes.Attribute)
900+
inferred_orig, inferred_copy = itertools.tee(node.func.expr.infer(context=context))
901+
if all(
902+
isinstance(
903+
inferred_node, (nodes.Dict, nodes.List, nodes.Set, objects.FrozenSet)
904+
)
905+
for inferred_node in inferred_orig
906+
):
907+
return inferred_copy
908+
909+
raise UseInferenceDefault()
910+
911+
895912
# Builtins inference
896913
register_builtin_transform(infer_bool, "bool")
897914
register_builtin_transform(infer_super, "super")
@@ -920,3 +937,10 @@ def _build_dict_with_elements(elements):
920937
inference_tip(_infer_object__new__decorator),
921938
_infer_object__new__decorator_check,
922939
)
940+
941+
AstroidManager().register_transform(
942+
nodes.Call,
943+
inference_tip(_infer_copy_method),
944+
lambda node: isinstance(node.func, nodes.Attribute)
945+
and node.func.attrname == "copy",
946+
)

astroid/brain/brain_crypt.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@
44

55
from astroid.brain.helpers import register_module_extender
66
from astroid.builder import parse
7-
from astroid.const import PY37_PLUS
87
from astroid.manager import AstroidManager
98

10-
if PY37_PLUS:
11-
# Since Python 3.7 Hashing Methods are added
12-
# dynamically to globals()
139

14-
def _re_transform():
15-
return parse(
16-
"""
17-
from collections import namedtuple
18-
_Method = namedtuple('_Method', 'name ident salt_chars total_size')
19-
20-
METHOD_SHA512 = _Method('SHA512', '6', 16, 106)
21-
METHOD_SHA256 = _Method('SHA256', '5', 16, 63)
22-
METHOD_BLOWFISH = _Method('BLOWFISH', 2, 'b', 22)
23-
METHOD_MD5 = _Method('MD5', '1', 8, 34)
24-
METHOD_CRYPT = _Method('CRYPT', None, 2, 13)
10+
def _re_transform():
11+
return parse(
2512
"""
26-
)
13+
from collections import namedtuple
14+
_Method = namedtuple('_Method', 'name ident salt_chars total_size')
15+
16+
METHOD_SHA512 = _Method('SHA512', '6', 16, 106)
17+
METHOD_SHA256 = _Method('SHA256', '5', 16, 63)
18+
METHOD_BLOWFISH = _Method('BLOWFISH', 2, 'b', 22)
19+
METHOD_MD5 = _Method('MD5', '1', 8, 34)
20+
METHOD_CRYPT = _Method('CRYPT', None, 2, 13)
21+
"""
22+
)
23+
2724

28-
register_module_extender(AstroidManager(), "crypt", _re_transform)
25+
register_module_extender(AstroidManager(), "crypt", _re_transform)

astroid/brain/brain_dataclasses.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from astroid import context, inference_tip
1919
from astroid.builder import parse
20-
from astroid.const import PY37_PLUS, PY39_PLUS
20+
from astroid.const import PY39_PLUS
2121
from astroid.exceptions import (
2222
AstroidSyntaxError,
2323
InferenceError,
@@ -449,19 +449,18 @@ def _infer_instance_from_annotation(
449449
yield klass.instantiate_class()
450450

451451

452-
if PY37_PLUS:
453-
AstroidManager().register_transform(
454-
ClassDef, dataclass_transform, is_decorated_with_dataclass
455-
)
452+
AstroidManager().register_transform(
453+
ClassDef, dataclass_transform, is_decorated_with_dataclass
454+
)
456455

457-
AstroidManager().register_transform(
458-
Call,
459-
inference_tip(infer_dataclass_field_call, raise_on_overwrite=True),
460-
_looks_like_dataclass_field_call,
461-
)
456+
AstroidManager().register_transform(
457+
Call,
458+
inference_tip(infer_dataclass_field_call, raise_on_overwrite=True),
459+
_looks_like_dataclass_field_call,
460+
)
462461

463-
AstroidManager().register_transform(
464-
Unknown,
465-
inference_tip(infer_dataclass_attribute, raise_on_overwrite=True),
466-
_looks_like_dataclass_attribute,
467-
)
462+
AstroidManager().register_transform(
463+
Unknown,
464+
inference_tip(infer_dataclass_attribute, raise_on_overwrite=True),
465+
_looks_like_dataclass_attribute,
466+
)

astroid/brain/brain_re.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from astroid import context, inference_tip, nodes
88
from astroid.brain.helpers import register_module_extender
99
from astroid.builder import _extract_single_node, parse
10-
from astroid.const import PY37_PLUS, PY39_PLUS, PY311_PLUS
10+
from astroid.const import PY39_PLUS, PY311_PLUS
1111
from astroid.manager import AstroidManager
1212

1313

@@ -90,7 +90,6 @@ def infer_pattern_match(
9090
return iter([class_def])
9191

9292

93-
if PY37_PLUS:
94-
AstroidManager().register_transform(
95-
nodes.Call, inference_tip(infer_pattern_match), _looks_like_pattern_or_match
96-
)
93+
AstroidManager().register_transform(
94+
nodes.Call, inference_tip(infer_pattern_match), _looks_like_pattern_or_match
95+
)

0 commit comments

Comments
 (0)