Skip to content

Commit

Permalink
Update astroid version to 3.1.0 (#9457)
Browse files Browse the repository at this point in the history
* 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 <jacobtylerwalls@gmail.com>
  • Loading branch information
cdce8p and jacobtylerwalls authored Feb 23, 2024
1 parent d4f0ef7 commit f499686
Show file tree
Hide file tree
Showing 34 changed files with 38 additions and 9 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9196.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Check ``TypeAlias`` and ``TypeVar`` (PEP 695) nodes for ``invalid-name``.

Refs #9196
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9457.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Update astroid version to 3.1.0.

Refs #9457
9 changes: 9 additions & 0 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ def visit_assignname( # pylint: disable=too-many-branches
if isinstance(assign_type, nodes.Comprehension):
self._check_name("inlinevar", node.name, node)

elif isinstance(assign_type, nodes.TypeVar):
self._check_name("typevar", node.name, node)

elif isinstance(assign_type, nodes.TypeAlias):
self._check_name("typealias", node.name, node)

# Check names defined in module scope
elif isinstance(frame, nodes.Module):
# Check names defined in Assign nodes
Expand Down Expand Up @@ -625,6 +631,9 @@ def _check_typevar(self, name: str, node: nodes.AssignName) -> None:
node.assign_type().value.elts[node.parent.elts.index(node)].keywords
)
args = node.assign_type().value.elts[node.parent.elts.index(node)].args
else: # PEP 695 generic type nodes
keywords = ()
args = ()

variance = TypeVarVariance.invariant
name_arg = None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [
# Also upgrade requirements_test_min.txt.
# Pinned to dev of second minor update to allow editable installs and fix primer issues,
# see https://github.com/pylint-dev/astroid/issues/1341
"astroid>=3.0.3,<=3.1.0-dev0",
"astroid>=3.1.0,<=3.2.0-dev0",
"isort>=4.2.5,<6,!=5.13.0",
"mccabe>=0.6,<0.8",
"tomli>=1.1.0;python_version<'3.11'",
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_min.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.[testutils,spelling]
# astroid dependency is also defined in pyproject.toml
astroid==3.0.3 # Pinned to a specific version for tests
astroid==3.1.0 # Pinned to a specific version for tests
typing-extensions~=4.9
py~=1.11.0
pytest~=7.4
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/i/import_error.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import-error:3:0:3:22::Unable to import 'totally_missing':UNDEFINED
import-error:21:4:21:26::Unable to import 'maybe_missing_2':UNDEFINED
no-name-in-module:33:0:33:49::No name 'syntax_error' in module 'functional.s.syntax':UNDEFINED
syntax-error:33:0:None:None::Cannot import 'functional.s.syntax.syntax_error' due to 'invalid syntax (<unknown>, line 1)':HIGH
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
multiple-imports:78:0:78:15::Multiple imports on one line (foo, bar):UNDEFINED
import-error:96:4:96:15::Unable to import 'foo2':UNDEFINED
2 changes: 1 addition & 1 deletion tests/functional/s/syntax/syntax_error.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
syntax-error:1:5:None:None::"Parsing failed: 'invalid syntax (<unknown>, line 1)'":HIGH
syntax-error:1:5:None:None::"Parsing failed: 'invalid syntax (syntax_error, line 1)'":HIGH
Empty file.
4 changes: 4 additions & 0 deletions tests/functional/t/type/typealias_naming_style_py312.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""PEP 695 generic typing nodes"""

type Point[T] = tuple[T, ...]
type point[T] = tuple[T, ...] # [invalid-name]
2 changes: 2 additions & 0 deletions tests/functional/t/type/typealias_naming_style_py312.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.12
1 change: 1 addition & 0 deletions tests/functional/t/type/typealias_naming_style_py312.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid-name:4:5:4:10::"Type alias name ""point"" doesn't conform to predefined naming style":HIGH
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/functional/t/type/typevar_naming_style_py312.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""PEP 695 generic typing nodes"""

type Point[T] = tuple[T, ...]
type Point[t] = tuple[t, ...] # [invalid-name]
2 changes: 2 additions & 0 deletions tests/functional/t/type/typevar_naming_style_py312.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.12
1 change: 1 addition & 0 deletions tests/functional/t/type/typevar_naming_style_py312.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid-name:4:11:4:12::"Type variable name ""t"" doesn't conform to predefined naming style":HIGH
6 changes: 3 additions & 3 deletions tests/functional/u/used/used_before_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ def turn_on2(**kwargs):
# Variables guarded by the same test when used.

# Always false
if __name__ == "__main__":
if 1 in []:
PERCENT = 20
SALE = True

if __name__ == "__main__":
if 1 in []:
print(PERCENT)

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


Expand Down
4 changes: 2 additions & 2 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def test_json_report_when_file_has_syntax_error(self) -> None:
assert message[key] == value
msg = message["message"].lower()
assert any(x in msg for x in ("expected ':'", "invalid syntax"))
assert "<unknown>" in msg
assert "syntax_error" in msg
assert "line 1" in msg

def test_json_report_when_file_is_missing(self) -> None:
Expand Down Expand Up @@ -610,7 +610,7 @@ def foobar(arg):

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

0 comments on commit f499686

Please sign in to comment.