From 032ab32b386866b301a6fc564ad874e7cb3f0698 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 20 May 2024 07:15:47 +0200 Subject: [PATCH] Update astroid to 3.2.2 (#9655) * Update astroid to 3.2.2 * Add tests for generic class syntax --- doc/whatsnew/fragments/9406.false_positive | 3 ++ pyproject.toml | 2 +- requirements_test_min.txt | 2 +- tests/functional/g/generic_class_syntax.py | 38 +++++++++++++++++++ .../g/generic_class_syntax_py312.py | 33 ++++++++++++++++ .../g/generic_class_syntax_py312.rc | 2 + .../g/generic_class_syntax_py312.txt | 2 + 7 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 doc/whatsnew/fragments/9406.false_positive create mode 100644 tests/functional/g/generic_class_syntax.py create mode 100644 tests/functional/g/generic_class_syntax_py312.py create mode 100644 tests/functional/g/generic_class_syntax_py312.rc create mode 100644 tests/functional/g/generic_class_syntax_py312.txt diff --git a/doc/whatsnew/fragments/9406.false_positive b/doc/whatsnew/fragments/9406.false_positive new file mode 100644 index 0000000000..0c85ef699c --- /dev/null +++ b/doc/whatsnew/fragments/9406.false_positive @@ -0,0 +1,3 @@ +Fix multiple false positives for generic class syntax added in Python 3.12 (PEP 695). + +Closes #9406 diff --git a/pyproject.toml b/pyproject.toml index e991138b10..21f6fe03aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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.2.1,<=3.3.0-dev0", + "astroid>=3.2.2,<=3.3.0-dev0", "isort>=4.2.5,<6,!=5.13.0", "mccabe>=0.6,<0.8", "tomli>=1.1.0;python_version<'3.11'", diff --git a/requirements_test_min.txt b/requirements_test_min.txt index c64f74f862..14b100c7c8 100644 --- a/requirements_test_min.txt +++ b/requirements_test_min.txt @@ -1,6 +1,6 @@ .[testutils,spelling] # astroid dependency is also defined in pyproject.toml -astroid==3.2.1 # Pinned to a specific version for tests +astroid==3.2.2 # Pinned to a specific version for tests typing-extensions~=4.11 py~=1.11.0 pytest~=7.4 diff --git a/tests/functional/g/generic_class_syntax.py b/tests/functional/g/generic_class_syntax.py new file mode 100644 index 0000000000..b7305965ac --- /dev/null +++ b/tests/functional/g/generic_class_syntax.py @@ -0,0 +1,38 @@ +# pylint: disable=missing-docstring,too-few-public-methods +from typing import Generic, TypeVar, Optional + +_T = TypeVar("_T") + + +class Entity(Generic[_T]): + last_update: Optional[int] = None + + def __init__(self, data: _T) -> None: + self.data = data + + +class Sensor(Entity[int]): + def __init__(self, data: int) -> None: + super().__init__(data) + + def async_update(self) -> None: + self.data = 2 + + if self.last_update is None: + pass + self.last_update = 2 + + +class Switch(Entity[int]): + def __init__(self, data: int) -> None: + Entity.__init__(self, data) + + +class Parent(Generic[_T]): + def __init__(self): + self.update_interval = 0 + + +class Child(Parent[_T]): + def func(self): + self.update_interval = None diff --git a/tests/functional/g/generic_class_syntax_py312.py b/tests/functional/g/generic_class_syntax_py312.py new file mode 100644 index 0000000000..bbfff1c6ad --- /dev/null +++ b/tests/functional/g/generic_class_syntax_py312.py @@ -0,0 +1,33 @@ +# pylint: disable=missing-docstring,too-few-public-methods +class Entity[_T: float]: + last_update: int | None = None + + def __init__(self, data: _T) -> None: # [undefined-variable] # false-positive + self.data = data + + +class Sensor(Entity[int]): + def __init__(self, data: int) -> None: + super().__init__(data) + + def async_update(self) -> None: + self.data = 2 + + if self.last_update is None: + pass + self.last_update = 2 + + +class Switch(Entity[int]): + def __init__(self, data: int) -> None: + Entity.__init__(self, data) + + +class Parent[_T]: + def __init__(self): + self.update_interval = 0 + + +class Child[_T](Parent[_T]): # [undefined-variable] # false-positive + def func(self): + self.update_interval = None diff --git a/tests/functional/g/generic_class_syntax_py312.rc b/tests/functional/g/generic_class_syntax_py312.rc new file mode 100644 index 0000000000..9c966d4bda --- /dev/null +++ b/tests/functional/g/generic_class_syntax_py312.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.12 diff --git a/tests/functional/g/generic_class_syntax_py312.txt b/tests/functional/g/generic_class_syntax_py312.txt new file mode 100644 index 0000000000..bd5fbbe7ee --- /dev/null +++ b/tests/functional/g/generic_class_syntax_py312.txt @@ -0,0 +1,2 @@ +undefined-variable:5:29:5:31:Entity.__init__:Undefined variable '_T':UNDEFINED +undefined-variable:31:23:31:25:Child:Undefined variable '_T':UNDEFINED