ruff/crates/ruff_linter/resources/test/fixtures/pyflakes/F811_31.py
Charlie Marsh 456d6a2fb2
Consider with blocks as single-item branches (#12311)
## 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.
2024-07-13 15:22:17 -04:00

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