Skip to content

Commit eada4e0

Browse files
committed
Merge branch 'main' of https://github.com/PyCQA/astroid into orelse-lineno
2 parents 2252bce + c1390d5 commit eada4e0

Some content is hidden

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

63 files changed

+1669
-1357
lines changed

.github/workflows/ci.yaml

+13-13
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
'requirements_test_brain.txt', 'requirements_test_pre_commit.txt') }}"
3434
- name: Restore Python virtual environment
3535
id: cache-venv
36-
uses: actions/[email protected].2
36+
uses: actions/[email protected].3
3737
with:
3838
path: venv
3939
key: >-
@@ -56,7 +56,7 @@ jobs:
5656
hashFiles('.pre-commit-config.yaml') }}"
5757
- name: Restore pre-commit environment
5858
id: cache-precommit
59-
uses: actions/[email protected].2
59+
uses: actions/[email protected].3
6060
with:
6161
path: ${{ env.PRE_COMMIT_CACHE }}
6262
key: >-
@@ -79,7 +79,7 @@ jobs:
7979
runs-on: ubuntu-latest
8080
timeout-minutes: 20
8181
strategy:
82-
fail-fast: true
82+
fail-fast: false
8383
matrix:
8484
python-version: [3.7, 3.8, 3.9, "3.10"]
8585
outputs:
@@ -104,7 +104,7 @@ jobs:
104104
'requirements_test_brain.txt') }}"
105105
- name: Restore Python virtual environment
106106
id: cache-venv
107-
uses: actions/[email protected].2
107+
uses: actions/[email protected].3
108108
with:
109109
path: venv
110110
key: >-
@@ -125,7 +125,7 @@ jobs:
125125
. venv/bin/activate
126126
pytest --cov --cov-report= tests/
127127
- name: Upload coverage artifact
128-
uses: actions/upload-artifact@v3.0.0
128+
uses: actions/upload-artifact@v3.1.0
129129
with:
130130
name: coverage-${{ matrix.python-version }}
131131
path: .coverage
@@ -153,7 +153,7 @@ jobs:
153153
'requirements_test_brain.txt') }}"
154154
- name: Restore Python virtual environment
155155
id: cache-venv
156-
uses: actions/[email protected].2
156+
uses: actions/[email protected].3
157157
with:
158158
path: venv
159159
key: >-
@@ -174,7 +174,7 @@ jobs:
174174
. venv/bin/activate
175175
pytest --cov --cov-report= tests/
176176
- name: Upload coverage artifact
177-
uses: actions/upload-artifact@v3.0.0
177+
uses: actions/upload-artifact@v3.1.0
178178
with:
179179
name: coverage-${{ matrix.python-version }}
180180
path: .coverage
@@ -200,7 +200,7 @@ jobs:
200200
python-version: ${{ matrix.python-version }}
201201
- name: Restore Python virtual environment
202202
id: cache-venv
203-
uses: actions/[email protected].2
203+
uses: actions/[email protected].3
204204
with:
205205
path: venv
206206
key:
@@ -231,9 +231,9 @@ jobs:
231231
timeout-minutes: 20
232232
needs: tests-linux
233233
strategy:
234-
fail-fast: true
234+
fail-fast: false
235235
matrix:
236-
python-version: [3.7, 3.8, 3.9, "3.10"]
236+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11-dev"]
237237
steps:
238238
- name: Set temp directory
239239
run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV
@@ -254,7 +254,7 @@ jobs:
254254
'requirements_test_brain.txt') }}"
255255
- name: Restore Python virtual environment
256256
id: cache-venv
257-
uses: actions/[email protected].2
257+
uses: actions/[email protected].3
258258
with:
259259
path: venv
260260
key: >-
@@ -282,7 +282,7 @@ jobs:
282282
strategy:
283283
fail-fast: false
284284
matrix:
285-
python-version: ["pypy-3.7", "pypy-3.8"]
285+
python-version: ["pypy-3.7", "pypy-3.8", "pypy-3.9"]
286286
steps:
287287
- name: Check out code from GitHub
288288
uses: actions/[email protected]
@@ -298,7 +298,7 @@ jobs:
298298
hashFiles('setup.cfg', 'requirements_test_min.txt') }}"
299299
- name: Restore Python virtual environment
300300
id: cache-venv
301-
uses: actions/[email protected].2
301+
uses: actions/[email protected].3
302302
with:
303303
path: venv
304304
key: >-

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repos:
3939
- id: isort
4040
exclude: tests/testdata
4141
- repo: https://github.com/Pierre-Sassoulas/black-disable-checker/
42-
rev: 1.0.1
42+
rev: v1.1.0
4343
hooks:
4444
- id: black-disable-checker
4545
exclude: tests/unittest_nodes_lineno.py
@@ -71,7 +71,7 @@ repos:
7171
]
7272
exclude: tests/testdata|conf.py
7373
- repo: https://github.com/pre-commit/mirrors-mypy
74-
rev: v0.950
74+
rev: v0.960
7575
hooks:
7676
- id: mypy
7777
name: mypy

ChangeLog

+27-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Release date: TBA
88

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

11-
* Made ``block_range`` of ``nodes.If``, ``nodes.For``, ``nodes.While``,
12-
and ``nodes.TryExcept`` respect ``else`` and ``finally``.
11+
* Fix detection of builtins on ``PyPy`` 3.9.
1312

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

@@ -18,20 +17,46 @@ Release date: TBA
1817

1918
Closes #1512
2019

20+
* Capture and log messages emitted by C extensions when importing them.
21+
This prevents contaminating programmatic output, e.g. pylint's JSON reporter.
22+
23+
Closes PyCQA/pylint#3518
24+
25+
* Remove dependency on ``pkg_resources`` from ``setuptools``.
26+
27+
Closes #1103
28+
2129
* Allowed ``AstroidManager.clear_cache`` to reload necessary brain plugins.
2230

31+
* Fixed incorrect inferences after rebuilding the builtins module, e.g. by calling
32+
``AstroidManager.clear_cache``.
33+
34+
Closes #1559
35+
36+
* On Python versions >= 3.9, ``astroid`` now understands subscripting
37+
builtin classes such as ``enumerate`` or ``staticmethod``.
38+
2339
* Rename ``ModuleSpec`` -> ``module_type`` constructor parameter to match attribute
2440
name and improve typing. Use ``type`` instead.
2541

42+
* Fixed pylint ``not-callable`` false positive with nested-tuple assignment in a for-loop.
43+
44+
Refs PyCQA/pylint#5113
45+
2646
* Infer the return value of the ``.copy()`` method on ``dict``, ``list``, ``set``,
2747
and ``frozenset``.
2848

2949
Closes #1403
3050

51+
* Fix test for Python ``3.11``. In some instances ``err.__traceback__`` will
52+
be uninferable now.
53+
3154
What's New in astroid 2.11.6?
3255
=============================
3356
Release date: TBA
3457

58+
* The Qt brain now correctly treats calling ``.disconnect()`` (with no
59+
arguments) on a slot as valid.
3560

3661
What's New in astroid 2.11.5?
3762
=============================

astroid/_ast.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
44

5+
from __future__ import annotations
6+
57
import ast
68
import sys
79
import types
810
from functools import partial
9-
from typing import Dict, List, NamedTuple, Optional, Type
11+
from typing import NamedTuple
1012

1113
from astroid.const import PY38_PLUS, Context
1214

1315
if sys.version_info >= (3, 8):
1416
# On Python 3.8, typed_ast was merged back into `ast`
15-
_ast_py3: Optional[types.ModuleType] = ast
17+
_ast_py3: types.ModuleType | None = ast
1618
else:
1719
try:
1820
import typed_ast.ast3 as _ast_py3
@@ -21,17 +23,17 @@
2123

2224

2325
class FunctionType(NamedTuple):
24-
argtypes: List[ast.expr]
26+
argtypes: list[ast.expr]
2527
returns: ast.expr
2628

2729

2830
class ParserModule(NamedTuple):
2931
module: types.ModuleType
30-
unary_op_classes: Dict[Type[ast.unaryop], str]
31-
cmp_op_classes: Dict[Type[ast.cmpop], str]
32-
bool_op_classes: Dict[Type[ast.boolop], str]
33-
bin_op_classes: Dict[Type[ast.operator], str]
34-
context_classes: Dict[Type[ast.expr_context], Context]
32+
unary_op_classes: dict[type[ast.unaryop], str]
33+
cmp_op_classes: dict[type[ast.cmpop], str]
34+
bool_op_classes: dict[type[ast.boolop], str]
35+
bin_op_classes: dict[type[ast.operator], str]
36+
context_classes: dict[type[ast.expr_context], Context]
3537

3638
def parse(self, string: str, type_comments: bool = True) -> ast.Module:
3739
if self.module is _ast_py3:
@@ -46,7 +48,7 @@ def parse(self, string: str, type_comments: bool = True) -> ast.Module:
4648
return parse_func(string)
4749

4850

49-
def parse_function_type_comment(type_comment: str) -> Optional[FunctionType]:
51+
def parse_function_type_comment(type_comment: str) -> FunctionType | None:
5052
"""Given a correct type comment, obtain a FunctionType object"""
5153
if _ast_py3 is None:
5254
return None
@@ -78,13 +80,13 @@ def get_parser_module(type_comments: bool = True) -> ParserModule:
7880

7981
def _unary_operators_from_module(
8082
module: types.ModuleType,
81-
) -> Dict[Type[ast.unaryop], str]:
83+
) -> dict[type[ast.unaryop], str]:
8284
return {module.UAdd: "+", module.USub: "-", module.Not: "not", module.Invert: "~"}
8385

8486

8587
def _binary_operators_from_module(
8688
module: types.ModuleType,
87-
) -> Dict[Type[ast.operator], str]:
89+
) -> dict[type[ast.operator], str]:
8890
binary_operators = {
8991
module.Add: "+",
9092
module.BitAnd: "&",
@@ -105,13 +107,13 @@ def _binary_operators_from_module(
105107

106108
def _bool_operators_from_module(
107109
module: types.ModuleType,
108-
) -> Dict[Type[ast.boolop], str]:
110+
) -> dict[type[ast.boolop], str]:
109111
return {module.And: "and", module.Or: "or"}
110112

111113

112114
def _compare_operators_from_module(
113115
module: types.ModuleType,
114-
) -> Dict[Type[ast.cmpop], str]:
116+
) -> dict[type[ast.cmpop], str]:
115117
return {
116118
module.Eq: "==",
117119
module.Gt: ">",
@@ -128,7 +130,7 @@ def _compare_operators_from_module(
128130

129131
def _contexts_from_module(
130132
module: types.ModuleType,
131-
) -> Dict[Type[ast.expr_context], Context]:
133+
) -> dict[type[ast.expr_context], Context]:
132134
return {
133135
module.Load: Context.Load,
134136
module.Store: Context.Store,

astroid/arguments.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
44

5-
from typing import Optional, Set
5+
from __future__ import annotations
66

77
from astroid import nodes
88
from astroid.bases import Instance
@@ -36,7 +36,7 @@ def __init__(
3636
self.argument_context_map = argument_context_map
3737
args = callcontext.args
3838
keywords = callcontext.keywords
39-
self.duplicated_keywords: Set[str] = set()
39+
self.duplicated_keywords: set[str] = set()
4040
self._unpacked_args = self._unpack_args(args, context=context)
4141
self._unpacked_kwargs = self._unpack_keywords(keywords, context=context)
4242

@@ -50,7 +50,7 @@ def __init__(
5050
}
5151

5252
@classmethod
53-
def from_call(cls, call_node, context: Optional[InferenceContext] = None):
53+
def from_call(cls, call_node, context: InferenceContext | None = None):
5454
"""Get a CallSite object from the given Call node.
5555
5656
context will be used to force a single inference path.
@@ -160,7 +160,7 @@ def infer_argument(self, funcnode, name, context):
160160
"""
161161
if name in self.duplicated_keywords:
162162
raise InferenceError(
163-
"The arguments passed to {func!r} " " have duplicate keywords.",
163+
"The arguments passed to {func!r} have duplicate keywords.",
164164
call_site=self,
165165
func=funcnode,
166166
arg=name,

astroid/brain/brain_builtin_inference.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

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

7+
from __future__ import annotations
8+
79
import itertools
10+
from collections.abc import Iterator
811
from functools import partial
9-
from typing import Iterator, Optional
1012

1113
from astroid import arguments, helpers, inference_tip, nodes, objects, util
1214
from astroid.builder import AstroidBuilder
@@ -534,7 +536,7 @@ def infer_callable(node, context=None):
534536

535537

536538
def infer_property(
537-
node: nodes.Call, context: Optional[InferenceContext] = None
539+
node: nodes.Call, context: InferenceContext | None = None
538540
) -> objects.Property:
539541
"""Understand `property` class
540542
@@ -894,7 +896,7 @@ def _build_dict_with_elements(elements):
894896

895897

896898
def _infer_copy_method(
897-
node: nodes.Call, context: Optional[InferenceContext] = None
899+
node: nodes.Call, context: InferenceContext | None = None
898900
) -> Iterator[nodes.NodeNG]:
899901
assert isinstance(node.func, nodes.Attribute)
900902
inferred_orig, inferred_copy = itertools.tee(node.func.expr.infer(context=context))

0 commit comments

Comments
 (0)