Skip to content

Commit

Permalink
Ignore relative imports in banned-api rules (#4024)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Apr 19, 2023
1 parent 13fda30 commit c4cda30
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
# import aliases are resolved
import typing as totally_not_typing
totally_not_typing.TypedDict

# relative imports are respected
from .typing import TypedDict
14 changes: 8 additions & 6 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,13 +1155,15 @@ where
}

if self.settings.rules.enabled(Rule::BannedApi) {
if let Some(module) = module {
for name in names {
flake8_tidy_imports::banned_api::name_is_banned(self, module, name);
if level.map_or(true, |level| level == 0) {
if let Some(module) = module {
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,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ TID251.py:33:1: TID251 `typing.TypedDict` is banned: Use typing_extensions.Typed
34 | import typing as totally_not_typing
35 | totally_not_typing.TypedDict
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID251
36 |
37 | # relative imports are respected
|


0 comments on commit c4cda30

Please sign in to comment.