Summary
spam/__init__.py
from .foo import Bar
print(foo.Bar)
spam/foo.py
ruff things this is an error.
% uvx ruff check ./spam/__init__.py --select=F821
F821 Undefined name `foo`
--> spam/__init__.py:3:7
|
1 | from .foo import Bar
2 |
3 | print(foo.Bar)
| ^^^
|
Found 1 error.
But it works fine:
% python3 -c 'import spam'
<class 'spam.foo.Bar'>
This works due to weird python behavior (https://docs.python.org/3/reference/import.html#submodules).
(See also microsoft/pyright#782, where pyright used to have this same bug).
Version
ruff 0.15.0 (ce5f7b6 2026-02-03)