Skip to content

Commit c4cda30

Browse files
Ignore relative imports in banned-api rules (#4024)
1 parent 13fda30 commit c4cda30

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

crates/ruff/resources/test/fixtures/flake8_tidy_imports/TID251.py

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
# import aliases are resolved
3232
import typing as totally_not_typing
3333
totally_not_typing.TypedDict
34+
35+
# relative imports are respected
36+
from .typing import TypedDict

crates/ruff/src/checkers/ast/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1155,13 +1155,15 @@ where
11551155
}
11561156

11571157
if self.settings.rules.enabled(Rule::BannedApi) {
1158-
if let Some(module) = module {
1159-
for name in names {
1160-
flake8_tidy_imports::banned_api::name_is_banned(self, module, name);
1158+
if level.map_or(true, |level| level == 0) {
1159+
if let Some(module) = module {
1160+
for name in names {
1161+
flake8_tidy_imports::banned_api::name_is_banned(self, module, name);
1162+
}
1163+
flake8_tidy_imports::banned_api::name_or_parent_is_banned(
1164+
self, module, stmt,
1165+
);
11611166
}
1162-
flake8_tidy_imports::banned_api::name_or_parent_is_banned(
1163-
self, module, stmt,
1164-
);
11651167
}
11661168
}
11671169

crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__banned_api__tests__banned_api_true_positives.snap

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ TID251.py:33:1: TID251 `typing.TypedDict` is banned: Use typing_extensions.Typed
113113
34 | import typing as totally_not_typing
114114
35 | totally_not_typing.TypedDict
115115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID251
116+
36 |
117+
37 | # relative imports are respected
116118
|
117119

118120

0 commit comments

Comments
 (0)