Ignore relative imports in `banned-api` rules (#4024)

This commit is contained in:
Charlie Marsh 2023-04-19 13:30:08 -04:00 committed by GitHub
parent 13fda30051
commit c4cda301aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View File

@ -31,3 +31,6 @@ typing.TypedDict.anything()
# import aliases are resolved # import aliases are resolved
import typing as totally_not_typing import typing as totally_not_typing
totally_not_typing.TypedDict totally_not_typing.TypedDict
# relative imports are respected
from .typing import TypedDict

View File

@ -1155,13 +1155,15 @@ where
} }
if self.settings.rules.enabled(Rule::BannedApi) { if self.settings.rules.enabled(Rule::BannedApi) {
if let Some(module) = module { if level.map_or(true, |level| level == 0) {
for name in names { if let Some(module) = module {
flake8_tidy_imports::banned_api::name_is_banned(self, module, name); for name in names {
flake8_tidy_imports::banned_api::name_is_banned(self, module, name);
}
flake8_tidy_imports::banned_api::name_or_parent_is_banned(
self, module, stmt,
);
} }
flake8_tidy_imports::banned_api::name_or_parent_is_banned(
self, module, stmt,
);
} }
} }

View File

@ -113,6 +113,8 @@ TID251.py:33:1: TID251 `typing.TypedDict` is banned: Use typing_extensions.Typed
34 | import typing as totally_not_typing 34 | import typing as totally_not_typing
35 | totally_not_typing.TypedDict 35 | totally_not_typing.TypedDict
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID251 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID251
36 |
37 | # relative imports are respected
| |