mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-28 10:50:26 +00:00
## Summary
Ensures that, e.g., the following is not considered a
redefinition-without-use:
```python
import contextlib
foo = None
with contextlib.suppress(ImportError):
from some_module import foo
```
Closes https://github.com/astral-sh/ruff/issues/12309.
21 lines
338 B
Python
21 lines
338 B
Python
"""Regression test for: https://github.com/astral-sh/ruff/issues/12309"""
|
|
|
|
import contextlib
|
|
|
|
foo = None
|
|
with contextlib.suppress(ImportError):
|
|
from some_module import foo
|
|
|
|
bar = None
|
|
try:
|
|
from some_module import bar
|
|
except ImportError:
|
|
pass
|
|
|
|
|
|
try:
|
|
baz = None
|
|
|
|
from some_module import baz
|
|
except ImportError:
|
|
pass
|