summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2023-02-01 01:14:32 +0100
committerGitHub <noreply@github.com>2023-02-01 01:14:32 +0100
commit1b5bba4508507da46a38aaea996976660b7ccca1 (patch)
treec32805bc2ce72d7625e32689e4b193e1c6e38cc7
parentc70285dfdfd22668de9cab7a85ef205fafa57aaf (diff)
downloadpylint-git-1b5bba4508507da46a38aaea996976660b7ccca1.tar.gz
Fix issues with new typing Union syntax (Py310) (#8122)
* Fix issues with new typing Union syntax (Py310) * Upgrade astroid to 2.14.1
-rw-r--r--doc/whatsnew/fragments/8119.bugfix3
-rw-r--r--pyproject.toml2
-rw-r--r--requirements_test_min.txt2
-rw-r--r--tests/functional/a/alternative/alternative_union_syntax_error.rc1
-rw-r--r--tests/functional/a/alternative/alternative_union_syntax_regession_8119.py24
-rw-r--r--tests/functional/a/alternative/alternative_union_syntax_regession_8119.rc2
-rw-r--r--tests/functional/w/wrong_exception_operation.py2
-rw-r--r--tests/functional/w/wrong_exception_operation.rc2
-rw-r--r--tests/functional/w/wrong_exception_operation.txt1
-rw-r--r--tests/functional/w/wrong_exception_operation_py37.py18
-rw-r--r--tests/functional/w/wrong_exception_operation_py37.rc3
-rw-r--r--tests/functional/w/wrong_exception_operation_py37.txt3
12 files changed, 60 insertions, 3 deletions
diff --git a/doc/whatsnew/fragments/8119.bugfix b/doc/whatsnew/fragments/8119.bugfix
new file mode 100644
index 000000000..8e5ff0878
--- /dev/null
+++ b/doc/whatsnew/fragments/8119.bugfix
@@ -0,0 +1,3 @@
+Fix issue with new typing Union syntax in runtime context for Python 3.10+.
+
+Closes #8119
diff --git a/pyproject.toml b/pyproject.toml
index d49b26dd0..3fa73da29 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -39,7 +39,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/PyCQA/astroid/issues/1341
- "astroid>=2.13.3,<=2.15.0-dev0",
+ "astroid>=2.14.1,<=2.16.0-dev0",
"isort>=4.2.5,<6",
"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 ff0b23999..d5764c033 100644
--- a/requirements_test_min.txt
+++ b/requirements_test_min.txt
@@ -1,6 +1,6 @@
-e .[testutils,spelling]
# astroid dependency is also defined in pyproject.toml
-astroid==2.13.3 # Pinned to a specific version for tests
+astroid==2.14.1 # Pinned to a specific version for tests
typing-extensions~=4.4
py~=1.11.0
pytest~=7.2
diff --git a/tests/functional/a/alternative/alternative_union_syntax_error.rc b/tests/functional/a/alternative/alternative_union_syntax_error.rc
index c4d51566d..44063ad8c 100644
--- a/tests/functional/a/alternative/alternative_union_syntax_error.rc
+++ b/tests/functional/a/alternative/alternative_union_syntax_error.rc
@@ -3,3 +3,4 @@ py-version=3.8
[testoptions]
min_pyver=3.8
+max_pyver=3.10
diff --git a/tests/functional/a/alternative/alternative_union_syntax_regession_8119.py b/tests/functional/a/alternative/alternative_union_syntax_regession_8119.py
new file mode 100644
index 000000000..8ec199958
--- /dev/null
+++ b/tests/functional/a/alternative/alternative_union_syntax_regession_8119.py
@@ -0,0 +1,24 @@
+"""Regression test for alternative Union syntax in runtime contexts.
+Syntax support was added in Python 3.10.
+
+The code snipped should not raise any errors.
+https://github.com/PyCQA/pylint/issues/8119
+"""
+# pylint: disable=missing-docstring,too-few-public-methods
+from typing import Generic, TypeVar
+
+T = TypeVar("T")
+
+
+class Coordinator(Generic[T]):
+ def __init__(self, update_interval=None) -> None:
+ self.update_interval = update_interval
+
+
+class Child(Coordinator[int | str]):
+ def __init__(self) -> None:
+ Coordinator.__init__(self, update_interval=2)
+
+ def _async_update_data(self):
+ assert self.update_interval
+ self.update_interval = 1
diff --git a/tests/functional/a/alternative/alternative_union_syntax_regession_8119.rc b/tests/functional/a/alternative/alternative_union_syntax_regession_8119.rc
new file mode 100644
index 000000000..68a8c8ef1
--- /dev/null
+++ b/tests/functional/a/alternative/alternative_union_syntax_regession_8119.rc
@@ -0,0 +1,2 @@
+[testoptions]
+min_pyver=3.10
diff --git a/tests/functional/w/wrong_exception_operation.py b/tests/functional/w/wrong_exception_operation.py
index 1c3c4e380..8078573c4 100644
--- a/tests/functional/w/wrong_exception_operation.py
+++ b/tests/functional/w/wrong_exception_operation.py
@@ -3,7 +3,7 @@
try:
1/0
-except (ValueError | TypeError): # [wrong-exception-operation]
+except (ValueError | TypeError): # [catching-non-exception,wrong-exception-operation]
pass
try:
diff --git a/tests/functional/w/wrong_exception_operation.rc b/tests/functional/w/wrong_exception_operation.rc
new file mode 100644
index 000000000..68a8c8ef1
--- /dev/null
+++ b/tests/functional/w/wrong_exception_operation.rc
@@ -0,0 +1,2 @@
+[testoptions]
+min_pyver=3.10
diff --git a/tests/functional/w/wrong_exception_operation.txt b/tests/functional/w/wrong_exception_operation.txt
index c92fcc2a2..dc3c21346 100644
--- a/tests/functional/w/wrong_exception_operation.txt
+++ b/tests/functional/w/wrong_exception_operation.txt
@@ -1,3 +1,4 @@
+catching-non-exception:6:8:6:30::"Catching an exception which doesn't inherit from Exception: ValueError | TypeError":UNDEFINED
wrong-exception-operation:6:8:6:30::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead?:UNDEFINED
wrong-exception-operation:11:8:11:30::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead?:UNDEFINED
wrong-exception-operation:17:8:17:30::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead?:UNDEFINED
diff --git a/tests/functional/w/wrong_exception_operation_py37.py b/tests/functional/w/wrong_exception_operation_py37.py
new file mode 100644
index 000000000..1c3c4e380
--- /dev/null
+++ b/tests/functional/w/wrong_exception_operation_py37.py
@@ -0,0 +1,18 @@
+# pylint: disable=missing-docstring, superfluous-parens
+
+
+try:
+ 1/0
+except (ValueError | TypeError): # [wrong-exception-operation]
+ pass
+
+try:
+ 1/0
+except (ValueError + TypeError): # [wrong-exception-operation]
+ pass
+
+
+try:
+ 1/0
+except (ValueError < TypeError): # [wrong-exception-operation]
+ pass
diff --git a/tests/functional/w/wrong_exception_operation_py37.rc b/tests/functional/w/wrong_exception_operation_py37.rc
new file mode 100644
index 000000000..dd83cc953
--- /dev/null
+++ b/tests/functional/w/wrong_exception_operation_py37.rc
@@ -0,0 +1,3 @@
+[testoptions]
+min_pyver=3.7
+max_pyver=3.10
diff --git a/tests/functional/w/wrong_exception_operation_py37.txt b/tests/functional/w/wrong_exception_operation_py37.txt
new file mode 100644
index 000000000..c92fcc2a2
--- /dev/null
+++ b/tests/functional/w/wrong_exception_operation_py37.txt
@@ -0,0 +1,3 @@
+wrong-exception-operation:6:8:6:30::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead?:UNDEFINED
+wrong-exception-operation:11:8:11:30::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead?:UNDEFINED
+wrong-exception-operation:17:8:17:30::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead?:UNDEFINED