forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement TID251 (banning modules & module members) (astral-sh#1436)
- Loading branch information
1 parent
bde12c3
commit 9d34da2
Showing
14 changed files
with
514 additions
and
10 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
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,33 @@ | ||
## Banned modules ## | ||
import cgi | ||
|
||
from cgi import * | ||
|
||
from cgi import a, b, c | ||
|
||
# banning a module also bans any submodules | ||
import cgi.foo.bar | ||
|
||
from cgi.foo import bar | ||
|
||
from cgi.foo.bar import * | ||
|
||
## Banned module members ## | ||
|
||
from typing import TypedDict | ||
|
||
import typing | ||
|
||
# attribute access is checked | ||
typing.TypedDict | ||
|
||
typing.TypedDict.anything | ||
|
||
# function calls are checked | ||
typing.TypedDict() | ||
|
||
typing.TypedDict.anything() | ||
|
||
# import aliases are resolved | ||
import typing as totally_not_typing | ||
totally_not_typing.TypedDict |
11 changes: 11 additions & 0 deletions
11
resources/test/fixtures/flake8_tidy_imports/TID251_false_positives.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,11 @@ | ||
# module members cannot be imported with that syntax | ||
import typing.TypedDict | ||
|
||
# we don't track reassignments | ||
import typing, other | ||
typing = other | ||
typing.TypedDict() | ||
|
||
# yet another false positive | ||
def foo(typing): | ||
typing.TypedDict() |
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
Oops, something went wrong.