Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker-py stubs #11749

Merged
merged 5 commits into from
Apr 12, 2024
Merged

Add docker-py stubs #11749

merged 5 commits into from
Apr 12, 2024

Conversation

kasium
Copy link
Contributor

@kasium kasium commented Apr 12, 2024

No description provided.

This comment has been minimized.

@kasium
Copy link
Contributor Author

kasium commented Apr 12, 2024

So the mypy_primer errors seem justified. Some invalid imports (they work at runtime due to side-effects but are not allowed). In addition in perfect, they seem to use decorators making an async method sync which is not correctly typed leading now to errors when DockerClient is no longer Any

This comment has been minimized.

This comment has been minimized.

@Viicos
Copy link
Contributor

Viicos commented Apr 12, 2024

There is already some precedent here: docker/docker-py#2796

@kasium
Copy link
Contributor Author

kasium commented Apr 12, 2024

There is already some precedent here: docker/docker-py#2796

I'm aware of this issue. There was no real progress since 3 years...

@srittau
Copy link
Collaborator

srittau commented Apr 12, 2024

Stubtest still has a few complaints.

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after a casual scan. One optional suggestion below.

stubs/docker/docker/constants.pyi Outdated Show resolved Hide resolved
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/dockerutils.py:98: error: Cannot find implementation or library stub for module named "docker"  [import-not-found]
+ src/prefect/utilities/dockerutils.py:431: error: Name "docker.Image" is not defined  [name-defined]
- src/prefect/infrastructure/container.py:47: error: Cannot find implementation or library stub for module named "docker"  [import-not-found]
- src/prefect/infrastructure/container.py:49: error: Cannot find implementation or library stub for module named "docker.models.containers"  [import-not-found]
+ src/prefect/infrastructure/container.py:508: error: Argument 1 to "_build_container_settings" of "DockerContainer" has incompatible type "Coroutine[Any, Any, DockerClient]"; expected "DockerClient"  [arg-type]
+ src/prefect/infrastructure/container.py:508: note: Maybe you forgot to use "await"?
+ src/prefect/infrastructure/container.py:510: error: Argument 1 to "_should_pull_image" of "DockerContainer" has incompatible type "Coroutine[Any, Any, DockerClient]"; expected "DockerClient"  [arg-type]
+ src/prefect/infrastructure/container.py:510: note: Maybe you forgot to use "await"?
+ src/prefect/infrastructure/container.py:512: error: Argument 1 to "_pull_image" of "DockerContainer" has incompatible type "Coroutine[Any, Any, DockerClient]"; expected "DockerClient"  [arg-type]
+ src/prefect/infrastructure/container.py:512: note: Maybe you forgot to use "await"?
+ src/prefect/infrastructure/container.py:514: error: Argument 1 to "_create_container" of "DockerContainer" has incompatible type "Coroutine[Any, Any, DockerClient]"; expected "DockerClient"  [arg-type]
+ src/prefect/infrastructure/container.py:514: note: Maybe you forgot to use "await"?
- src/prefect/infrastructure/container.py:520: error: "Coroutine[Any, Any, Any]" has no attribute "networks"  [attr-defined]
+ src/prefect/infrastructure/container.py:520: error: "Coroutine[Any, Any, DockerClient]" has no attribute "networks"  [attr-defined]
- src/prefect/infrastructure/container.py:637: error: Cannot find implementation or library stub for module named "docker.errors"  [import-not-found]
+ src/prefect/infrastructure/container.py:520: note: Maybe you forgot to use "await"?
+ src/prefect/infrastructure/container.py:666: error: Incompatible types in assignment (expression has type "None", variable has type "Container")  [assignment]
+ src/prefect/infrastructure/container.py:678: error: Missing return statement  [return]
+ src/prefect/infrastructure/container.py:687: error: Incompatible types in "yield" (actual type "Container", expected type "None")  [misc]
+ src/prefect/infrastructure/container.py:713: error: Incompatible types in "yield" (actual type "Container", expected type "None")  [misc]
+ src/prefect/infrastructure/container.py:719: error: Incompatible types in "yield" (actual type "Container", expected type "None")  [misc]
- src/prefect/cli/dev.py:405: error: Cannot find implementation or library stub for module named "docker"  [import-not-found]
- src/prefect/cli/dev.py:406: error: Cannot find implementation or library stub for module named "docker.models.containers"  [import-not-found]

paasta (https://github.com/yelp/paasta)
+ paasta_tools/utils.py:76: error: Module "docker" has no attribute "Client"; maybe "APIClient"?  [attr-defined]
+ paasta_tools/utils.py:3490: error: Unexpected keyword argument "assert_hostname" for "kwargs_from_env"  [call-arg]

dragonchain (https://github.com/dragonchain/dragonchain)
+ dragonchain/job_processor/contract_job.py:251:16: error: Module has no attribute "errors"  [attr-defined]
+ dragonchain/job_processor/contract_job.py:268:17: error: Module has no attribute "errors"  [attr-defined]
+ dragonchain/job_processor/contract_job.py:280:16: error: Module has no attribute "errors"  [attr-defined]
+ dragonchain/job_processor/contract_job_utest.py:251:13: error: "Callable[[Any, Optional[str], bool, KwArg(Any)], Any]" has no attribute "assert_called"  [attr-defined]

@srittau srittau merged commit bc8fc36 into python:main Apr 12, 2024
43 checks passed
@adamtheturtle
Copy link
Contributor

Thank you @kasium and @srittau !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants