-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-pyi
] Implement PYI049 (#6136)
## Summary Checks for the presence of unused private `typing.TypedDict` definitions. ref #848 ## Test Plan Snapshots and manual runs of flake8
- Loading branch information
1 parent
7838d8c
commit e0d5c75
Showing
9 changed files
with
164 additions
and
0 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,18 @@ | ||
import typing | ||
from typing import TypedDict | ||
|
||
|
||
class _UnusedTypedDict(TypedDict): | ||
foo: str | ||
|
||
|
||
class _UnusedTypedDict2(typing.TypedDict): | ||
bar: int | ||
|
||
|
||
class _UsedTypedDict(TypedDict): | ||
foo: bytes | ||
|
||
|
||
class _CustomClass(_UsedTypedDict): | ||
bar: list[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,32 @@ | ||
import sys | ||
import typing | ||
from typing import TypedDict | ||
|
||
|
||
class _UnusedTypedDict(TypedDict): | ||
foo: str | ||
|
||
|
||
class _UnusedTypedDict2(typing.TypedDict): | ||
bar: int | ||
|
||
|
||
# OK | ||
class _UsedTypedDict(TypedDict): | ||
foo: bytes | ||
|
||
|
||
class _CustomClass(_UsedTypedDict): | ||
bar: list[int] | ||
|
||
|
||
if sys.version_info >= (3, 10): | ||
class _UsedTypedDict2(TypedDict): | ||
foo: int | ||
else: | ||
class _UsedTypedDict2(TypedDict): | ||
foo: float | ||
|
||
|
||
class _CustomClass2(_UsedTypedDict2): | ||
bar: list[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
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
4 changes: 4 additions & 0 deletions
4
...ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI049_PYI049.py.snap
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 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_pyi/mod.rs | ||
--- | ||
|
18 changes: 18 additions & 0 deletions
18
...uff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI049_PYI049.pyi.snap
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,18 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_pyi/mod.rs | ||
--- | ||
PYI049.pyi:6:7: PYI049 Private TypedDict `_UnusedTypedDict` is never used | ||
| | ||
6 | class _UnusedTypedDict(TypedDict): | ||
| ^^^^^^^^^^^^^^^^ PYI049 | ||
7 | foo: str | ||
| | ||
|
||
PYI049.pyi:10:7: PYI049 Private TypedDict `_UnusedTypedDict2` is never used | ||
| | ||
10 | class _UnusedTypedDict2(typing.TypedDict): | ||
| ^^^^^^^^^^^^^^^^^ PYI049 | ||
11 | bar: int | ||
| | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.