summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2023-02-03 03:23:05 -0500
committerGitHub <noreply@github.com>2023-02-03 08:23:05 +0000
commitffbd2e068ed3da4caf83df81ab44ac03866c77b5 (patch)
tree11861f47c64d479118026700586a718d066c5519 /tests
parent9490a38b62d5c8750d74a186b644e060de8313d2 (diff)
downloadpylint-git-ffbd2e068ed3da4caf83df81ab44ac03866c77b5.tar.gz
Add some test cases for redundant type check (#8136)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/ext/typing/redundant_typehint_argument.py15
-rw-r--r--tests/functional/ext/typing/redundant_typehint_argument.txt4
-rw-r--r--tests/functional/ext/typing/redundant_typehint_argument_py310.py40
-rw-r--r--tests/functional/ext/typing/redundant_typehint_argument_py310.rc6
-rw-r--r--tests/functional/ext/typing/redundant_typehint_argument_py310.txt14
5 files changed, 78 insertions, 1 deletions
diff --git a/tests/functional/ext/typing/redundant_typehint_argument.py b/tests/functional/ext/typing/redundant_typehint_argument.py
index 2b423dc7a..e4814ed5f 100644
--- a/tests/functional/ext/typing/redundant_typehint_argument.py
+++ b/tests/functional/ext/typing/redundant_typehint_argument.py
@@ -1,5 +1,5 @@
""""Checks for redundant Union typehints in assignments"""
-# pylint: disable=deprecated-typing-alias,consider-alternative-union-syntax,consider-using-alias
+# pylint: disable=deprecated-typing-alias,consider-alternative-union-syntax,consider-using-alias,invalid-name,unused-argument,missing-function-docstring
from __future__ import annotations
from typing import Union, Optional, Sequence
@@ -19,3 +19,16 @@ ANSWER_9: str | int | None | int | bool = 9 # [redundant-typehint-argument]
ANSWER_10: dict | list[int] | float | str | int | bool = 10
# +1: [redundant-typehint-argument]
ANSWER_11: list[int] | dict[int] | dict[list[int]] | list[str] | list[str] = ['string']
+
+# Multiple warnings for the same repeated type
+# +1: [redundant-typehint-argument, redundant-typehint-argument, redundant-typehint-argument]
+x: int | int | int | int
+
+# No warning for redundant types in compound type (yet !)
+z: dict[int | int, str | str]
+
+# +1: [redundant-typehint-argument]
+zz: dict[int | int, str | str] | dict[int | int, str | str]
+
+# No warnings for redundant types in function signature (yet !)
+def f(p: int | int) -> str | str: ...
diff --git a/tests/functional/ext/typing/redundant_typehint_argument.txt b/tests/functional/ext/typing/redundant_typehint_argument.txt
index e76dc562d..cf4bb78c2 100644
--- a/tests/functional/ext/typing/redundant_typehint_argument.txt
+++ b/tests/functional/ext/typing/redundant_typehint_argument.txt
@@ -7,3 +7,7 @@ redundant-typehint-argument:16:0:16:82::Type `list[str]` is used more than once
redundant-typehint-argument:17:0:17:23::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
redundant-typehint-argument:18:0:18:43::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
redundant-typehint-argument:21:0:21:87::Type `list[str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:31:0:31:59::Type `dict[int | int, str | str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
diff --git a/tests/functional/ext/typing/redundant_typehint_argument_py310.py b/tests/functional/ext/typing/redundant_typehint_argument_py310.py
new file mode 100644
index 000000000..599f88283
--- /dev/null
+++ b/tests/functional/ext/typing/redundant_typehint_argument_py310.py
@@ -0,0 +1,40 @@
+""""Checks for redundant Union typehints in assignments"""
+# pylint: disable=deprecated-typing-alias,consider-alternative-union-syntax,consider-using-alias,invalid-name,unused-argument,missing-function-docstring
+
+from __future__ import annotations
+from typing import Union, Optional, Sequence
+
+# +1: [redundant-typehint-argument, redundant-typehint-argument]
+ANSWER_0: Union[int, int, str, bool, float, str] = 0
+ANSWER_1: Optional[int] = 1
+ANSWER_2: Sequence[int] = [2]
+ANSWER_3: Union[list[int], str, int, bool, list[int]] = 3 # [redundant-typehint-argument]
+ANSWER_4: Optional[None] = None # [redundant-typehint-argument]
+ANSWER_5: Optional[list[int]] = None
+ANSWER_6: Union[None, None] = None # [redundant-typehint-argument]
+# +1: [redundant-typehint-argument]
+ANSWER_7: Union[list[int], dict[int], dict[list[int]], list[str], list[str]] = [7]
+ANSWER_8: int | int = 8 # [redundant-typehint-argument]
+ANSWER_9: str | int | None | int | bool = 9 # [redundant-typehint-argument]
+ANSWER_10: dict | list[int] | float | str | int | bool = 10
+# +1: [redundant-typehint-argument]
+ANSWER_11: list[int] | dict[int] | dict[list[int]] | list[str] | list[str] = ['string']
+
+# Multiple warnings for the same repeated type
+# +1: [redundant-typehint-argument, redundant-typehint-argument, redundant-typehint-argument]
+x: int | int | int | int
+
+# No warning for type alias (yet !)
+Q = int | int
+QQ = Q | Q
+
+q: Q | Q # [redundant-typehint-argument]
+
+# No warning for redundant types in compound type (yet !)
+z: dict[int | int, str | str]
+
+# +1: [redundant-typehint-argument]
+zz: dict[int | int, str | str] | dict[int | int, str | str]
+
+# No warnings for redundant types in function signature (yet !)
+def f(p: int | int) -> str | str: ...
diff --git a/tests/functional/ext/typing/redundant_typehint_argument_py310.rc b/tests/functional/ext/typing/redundant_typehint_argument_py310.rc
new file mode 100644
index 000000000..3c06fa433
--- /dev/null
+++ b/tests/functional/ext/typing/redundant_typehint_argument_py310.rc
@@ -0,0 +1,6 @@
+[main]
+py-version=3.10
+load-plugins=pylint.extensions.typing
+
+[testoptions]
+min_pyver=3.10
diff --git a/tests/functional/ext/typing/redundant_typehint_argument_py310.txt b/tests/functional/ext/typing/redundant_typehint_argument_py310.txt
new file mode 100644
index 000000000..39e5c3591
--- /dev/null
+++ b/tests/functional/ext/typing/redundant_typehint_argument_py310.txt
@@ -0,0 +1,14 @@
+redundant-typehint-argument:8:0:8:52::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:8:0:8:52::Type `str` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:11:0:11:57::Type `list[int]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:12:10:12:24::Type `None` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:14:0:14:34::Type `None` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:16:0:16:82::Type `list[str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:17:0:17:23::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:18:0:18:43::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:21:0:21:87::Type `list[str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:25:0:25:24::Type `int` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:31:0:31:8::Type `Q` is used more than once in union type annotation. Remove redundant typehints.:HIGH
+redundant-typehint-argument:37:0:37:59::Type `dict[int | int, str | str]` is used more than once in union type annotation. Remove redundant typehints.:HIGH