Skip to content

Commit f499686

Browse files
Update astroid version to 3.1.0 (#9457)
* Update astroid version to 3.1.0 * Fix SyntaxError test outputs * Fix self tests * Prevent `invalid-name` for PEP 695 nodes Co-authored-by: Jacob Walls <[email protected]>
1 parent d4f0ef7 commit f499686

34 files changed

+38
-9
lines changed

doc/whatsnew/fragments/9196.feature

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Check ``TypeAlias`` and ``TypeVar`` (PEP 695) nodes for ``invalid-name``.
2+
3+
Refs #9196

doc/whatsnew/fragments/9457.internal

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Update astroid version to 3.1.0.
2+
3+
Refs #9457

pylint/checkers/base/name_checker/checker.py

+9
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ def visit_assignname( # pylint: disable=too-many-branches
409409
if isinstance(assign_type, nodes.Comprehension):
410410
self._check_name("inlinevar", node.name, node)
411411

412+
elif isinstance(assign_type, nodes.TypeVar):
413+
self._check_name("typevar", node.name, node)
414+
415+
elif isinstance(assign_type, nodes.TypeAlias):
416+
self._check_name("typealias", node.name, node)
417+
412418
# Check names defined in module scope
413419
elif isinstance(frame, nodes.Module):
414420
# Check names defined in Assign nodes
@@ -625,6 +631,9 @@ def _check_typevar(self, name: str, node: nodes.AssignName) -> None:
625631
node.assign_type().value.elts[node.parent.elts.index(node)].keywords
626632
)
627633
args = node.assign_type().value.elts[node.parent.elts.index(node)].args
634+
else: # PEP 695 generic type nodes
635+
keywords = ()
636+
args = ()
628637

629638
variance = TypeVarVariance.invariant
630639
name_arg = None

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = [
4141
# Also upgrade requirements_test_min.txt.
4242
# Pinned to dev of second minor update to allow editable installs and fix primer issues,
4343
# see https://github.com/pylint-dev/astroid/issues/1341
44-
"astroid>=3.0.3,<=3.1.0-dev0",
44+
"astroid>=3.1.0,<=3.2.0-dev0",
4545
"isort>=4.2.5,<6,!=5.13.0",
4646
"mccabe>=0.6,<0.8",
4747
"tomli>=1.1.0;python_version<'3.11'",

requirements_test_min.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.[testutils,spelling]
22
# astroid dependency is also defined in pyproject.toml
3-
astroid==3.0.3 # Pinned to a specific version for tests
3+
astroid==3.1.0 # Pinned to a specific version for tests
44
typing-extensions~=4.9
55
py~=1.11.0
66
pytest~=7.4

tests/functional/i/import_error.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import-error:3:0:3:22::Unable to import 'totally_missing':UNDEFINED
22
import-error:21:4:21:26::Unable to import 'maybe_missing_2':UNDEFINED
33
no-name-in-module:33:0:33:49::No name 'syntax_error' in module 'functional.s.syntax':UNDEFINED
4-
syntax-error:33:0:None:None::Cannot import 'functional.s.syntax.syntax_error' due to 'invalid syntax (<unknown>, line 1)':HIGH
4+
syntax-error:33:0:None:None::Cannot import 'functional.s.syntax.syntax_error' due to 'invalid syntax (functional.s.syntax.syntax_error, line 1)':HIGH
55
multiple-imports:78:0:78:15::Multiple imports on one line (foo, bar):UNDEFINED
66
import-error:96:4:96:15::Unable to import 'foo2':UNDEFINED
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
syntax-error:1:5:None:None::"Parsing failed: 'invalid syntax (<unknown>, line 1)'":HIGH
1+
syntax-error:1:5:None:None::"Parsing failed: 'invalid syntax (syntax_error, line 1)'":HIGH

tests/functional/t/type/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""PEP 695 generic typing nodes"""
2+
3+
type Point[T] = tuple[T, ...]
4+
type point[T] = tuple[T, ...] # [invalid-name]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
min_pyver=3.12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invalid-name:4:5:4:10::"Type alias name ""point"" doesn't conform to predefined naming style":HIGH
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""PEP 695 generic typing nodes"""
2+
3+
type Point[T] = tuple[T, ...]
4+
type Point[t] = tuple[t, ...] # [invalid-name]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[testoptions]
2+
min_pyver=3.12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invalid-name:4:11:4:12::"Type variable name ""t"" doesn't conform to predefined naming style":HIGH

tests/functional/u/used/used_before_assignment.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ def turn_on2(**kwargs):
132132
# Variables guarded by the same test when used.
133133

134134
# Always false
135-
if __name__ == "__main__":
135+
if 1 in []:
136136
PERCENT = 20
137137
SALE = True
138138

139-
if __name__ == "__main__":
139+
if 1 in []:
140140
print(PERCENT)
141141

142142
# Different test
143-
if __name__ is None:
143+
if 1 in [1]:
144144
print(SALE) # [used-before-assignment]
145145

146146

tests/test_self.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def test_json_report_when_file_has_syntax_error(self) -> None:
372372
assert message[key] == value
373373
msg = message["message"].lower()
374374
assert any(x in msg for x in ("expected ':'", "invalid syntax"))
375-
assert "<unknown>" in msg
375+
assert "syntax_error" in msg
376376
assert "line 1" in msg
377377

378378
def test_json_report_when_file_is_missing(self) -> None:
@@ -610,7 +610,7 @@ def foobar(arg):
610610

611611
def test_stdin_syntax_error(self) -> None:
612612
expected_output = """************* Module a
613-
a.py:1:4: E0001: Parsing failed: 'invalid syntax (<unknown>, line 1)' (syntax-error)"""
613+
a.py:1:4: E0001: Parsing failed: 'invalid syntax (a, line 1)' (syntax-error)"""
614614
with mock.patch(
615615
"pylint.lint.pylinter._read_stdin", return_value="for\n"
616616
) as mock_stdin:

0 commit comments

Comments
 (0)