mirror of https://github.com/astral-sh/ruff
Include ImportError in non-fixable try-catch imports (#4793)
This commit is contained in:
parent
be740106e0
commit
b7038cee13
|
|
@ -1976,10 +1976,17 @@ where
|
|||
let mut handled_exceptions = Exceptions::empty();
|
||||
for type_ in extract_handled_exceptions(handlers) {
|
||||
if let Some(call_path) = self.semantic_model.resolve_call_path(type_) {
|
||||
if call_path.as_slice() == ["", "NameError"] {
|
||||
handled_exceptions |= Exceptions::NAME_ERROR;
|
||||
} else if call_path.as_slice() == ["", "ModuleNotFoundError"] {
|
||||
handled_exceptions |= Exceptions::MODULE_NOT_FOUND_ERROR;
|
||||
match call_path.as_slice() {
|
||||
["", "NameError"] => {
|
||||
handled_exceptions |= Exceptions::NAME_ERROR;
|
||||
}
|
||||
["", "ModuleNotFoundError"] => {
|
||||
handled_exceptions |= Exceptions::MODULE_NOT_FOUND_ERROR;
|
||||
}
|
||||
["", "ImportError"] => {
|
||||
handled_exceptions |= Exceptions::IMPORT_ERROR;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ F401_10.py:6:16: F401 `orjson` imported but unused; consider using `importlib.ut
|
|||
|
|
||||
= help: Remove unused import: `orjson`
|
||||
|
||||
F401_10.py:15:16: F401 [*] `orjson` imported but unused
|
||||
F401_10.py:15:16: F401 `orjson` imported but unused; consider using `importlib.util.find_spec` to test for availability
|
||||
|
|
||||
15 | def import_error():
|
||||
16 | try:
|
||||
|
|
@ -23,13 +23,4 @@ F401_10.py:15:16: F401 [*] `orjson` imported but unused
|
|||
|
|
||||
= help: Remove unused import: `orjson`
|
||||
|
||||
ℹ Suggested fix
|
||||
12 12 |
|
||||
13 13 | def import_error():
|
||||
14 14 | try:
|
||||
15 |- import orjson
|
||||
16 15 |
|
||||
17 16 | return True
|
||||
18 17 | except ImportError:
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue