-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for
unnecessary-default-type-args
(#9938)
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
- Loading branch information
1 parent
bd97b93
commit b28c1f6
Showing
23 changed files
with
119 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from collections.abc import AsyncGenerator, Generator | ||
|
||
a1: AsyncGenerator[int, None] # [unnecessary-default-type-args] | ||
b1: Generator[int, None, None] # [unnecessary-default-type-args] |
6 changes: 6 additions & 0 deletions
6
doc/data/messages/u/unnecessary-default-type-args/details.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
At the moment, this check only works for ``Generator`` and ``AsyncGenerator``. | ||
|
||
Starting with Python 3.13, the ``SendType`` and ``ReturnType`` default to ``None``. | ||
As such it's no longer necessary to specify them. The ``collections.abc`` variants | ||
don't validate the number of type arguments. Therefore the defaults for these | ||
can be used in earlier versions as well. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from collections.abc import AsyncGenerator, Generator | ||
|
||
a1: AsyncGenerator[int] | ||
b1: Generator[int] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[main] | ||
load-plugins=pylint.extensions.typing |
2 changes: 2 additions & 0 deletions
2
doc/data/messages/u/unnecessary-default-type-args/related.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- `Python documentation for AsyncGenerator <https://docs.python.org/3.13/library/typing.html#typing.AsyncGenerator>`_ | ||
- `Python documentation for Generator <https://docs.python.org/3.13/library/typing.html#typing.Generator>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Add ``unnecessary-default-type-args`` to the ``typing`` extension to detect the use | ||
of unnecessary default type args for ``typing.Generator`` and ``typing.AsyncGenerator``. | ||
|
||
Refs #9938 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/functional/ext/typing/unnecessary_default_type_args.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# pylint: disable=missing-docstring,deprecated-typing-alias | ||
import collections.abc as ca | ||
import typing as t | ||
|
||
a1: t.Generator[int, str, str] | ||
a2: t.Generator[int, None, None] | ||
a3: t.Generator[int] | ||
b1: t.AsyncGenerator[int, str] | ||
b2: t.AsyncGenerator[int, None] | ||
b3: t.AsyncGenerator[int] | ||
|
||
c1: ca.Generator[int, str, str] | ||
c2: ca.Generator[int, None, None] # [unnecessary-default-type-args] | ||
c3: ca.Generator[int] | ||
d1: ca.AsyncGenerator[int, str] | ||
d2: ca.AsyncGenerator[int, None] # [unnecessary-default-type-args] | ||
d3: ca.AsyncGenerator[int] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[main] | ||
py-version=3.10 | ||
load-plugins=pylint.extensions.typing |
2 changes: 2 additions & 0 deletions
2
tests/functional/ext/typing/unnecessary_default_type_args.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
unnecessary-default-type-args:13:4:13:33::Type `ca.Generator[int, None, None]` has unnecessary default type args. Change it to `ca.Generator[int]`.:HIGH | ||
unnecessary-default-type-args:16:4:16:32::Type `ca.AsyncGenerator[int, None]` has unnecessary default type args. Change it to `ca.AsyncGenerator[int]`.:HIGH |
17 changes: 17 additions & 0 deletions
17
tests/functional/ext/typing/unnecessary_default_type_args_py313.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# pylint: disable=missing-docstring,deprecated-typing-alias | ||
import collections.abc as ca | ||
import typing as t | ||
|
||
a1: t.Generator[int, str, str] | ||
a2: t.Generator[int, None, None] # [unnecessary-default-type-args] | ||
a3: t.Generator[int] | ||
b1: t.AsyncGenerator[int, str] | ||
b2: t.AsyncGenerator[int, None] # [unnecessary-default-type-args] | ||
b3: t.AsyncGenerator[int] | ||
|
||
c1: ca.Generator[int, str, str] | ||
c2: ca.Generator[int, None, None] # [unnecessary-default-type-args] | ||
c3: ca.Generator[int] | ||
d1: ca.AsyncGenerator[int, str] | ||
d2: ca.AsyncGenerator[int, None] # [unnecessary-default-type-args] | ||
d3: ca.AsyncGenerator[int] |
3 changes: 3 additions & 0 deletions
3
tests/functional/ext/typing/unnecessary_default_type_args_py313.rc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[main] | ||
py-version=3.13 | ||
load-plugins=pylint.extensions.typing |
4 changes: 4 additions & 0 deletions
4
tests/functional/ext/typing/unnecessary_default_type_args_py313.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
unnecessary-default-type-args:6:4:6:32::Type `t.Generator[int, None, None]` has unnecessary default type args. Change it to `t.Generator[int]`.:HIGH | ||
unnecessary-default-type-args:9:4:9:31::Type `t.AsyncGenerator[int, None]` has unnecessary default type args. Change it to `t.AsyncGenerator[int]`.:HIGH | ||
unnecessary-default-type-args:13:4:13:33::Type `ca.Generator[int, None, None]` has unnecessary default type args. Change it to `ca.Generator[int]`.:HIGH | ||
unnecessary-default-type-args:16:4:16:32::Type `ca.AsyncGenerator[int, None]` has unnecessary default type args. Change it to `ca.AsyncGenerator[int]`.:HIGH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters