`docker.types` reported as `possibly-missing-attribute` after `import docker; from docker.types import Ulimit`
Question
Hello,
I have the following test.py:
import docker
from docker.types import Ulimit
docker.types.Ulimit(name='nproc', soft=1024)
Ulimit(name='nproc', soft=1024)
and I have docker==7.1.0 installed in an activte venv.
When I run ty (ty 0.0.1-alpha.28 (8c342496a 2025-11-25)) I get:
> ty check test.py
warning[possibly-missing-attribute]: Submodule `types` may not be available as an attribute on module `docker`
--> test.py:4:1
|
2 | from docker.types import Ulimit
3 |
4 | docker.types.Ulimit(name='nproc', soft=1024)
| ^^^^^^^^^^^^
5 | Ulimit(name='nproc', soft=1024)
|
help: Consider explicitly importing `docker.types`
info: rule `possibly-missing-attribute` is enabled by default
Found 1 diagnostic
pyright (pyright 1.1.407) also complains:
pyright test.py
/private/tmp/q/test.py
/private/tmp/q/test.py:4:8 - error: "types" is not a known attribute of module "docker" (reportAttributeAccessIssue)
After installing stubs, mypy (mypy 1.18.2 (compiled: yes)) doesn't complain:
> mypy test.py
Success: no issues found in 1 source file
python (Python 3.12.11 on macOS) itself doesn't complain:
> python test.py
>
Looking at https://github.com/docker/docker-py/blob/7.1.0/docker/init.py there is no import that create types but there is an adjacent types/ directory that contains https://github.com/docker/docker-py/blob/7.1.0/docker/types/init.py and that imports Ulimit.
I have done searches https://github.com/astral-sh/ty/issues?q=unresolved-attribute and https://github.com/astral-sh/ty/issues?q=possibly-missing-attribute but I can't find an existing duplicate but I'm sure one must already exist. Can you point me in the right direction?
Version
ty 0.0.1-alpha.28 (8c342496a 2025-11-25)
We don't have an issue for this currently, but this would be fixed by https://github.com/astral-sh/ruff/pull/21583, which is a joint effort by me and @Gankra :-)
@AlexWaygood Ah a PR is even better! Thanks for pointing me towards it.
This issue is probably the most common one found in my projects.