aio-libs / aiodocker

Python Docker API client based on asyncio and aiohttp
Other
441 stars 101 forks source link

Use `TYPE_CHECKING` flag to avoid importing from `typing_extensions` at run time #877

Closed edgarrmondragon closed 4 months ago

edgarrmondragon commented 4 months ago

What do these changes do?

Use TYPE_CHECKING flag to avoid importing from typing_extensions at run time

Are there changes in behavior for the user?

typing_extensions would no longer be importable from this package, but users shouldn't be doing that anyway :)

Related issue number

https://github.com/aio-libs/aiodocker/issues/876

Checklist

Closes https://github.com/aio-libs/aiodocker/issues/876

edgarrmondragon commented 4 months ago

FWIW it seems the pre-commit hook for mypy is missing a bunch of actual typing problems, but it's probably beyond the scope of this PR to fix those:

$ mypy aiodocker tests
aiodocker/stream.py:83: error: Item "None" of "ResponseHandler | None" has no attribute "transport"  [union-attr]
aiodocker/stream.py:83: error: Item "None" of "Transport | Any | None" has no attribute "get_extra_info"  [union-attr]
aiodocker/stream.py:90: error: Argument 1 to "FlowControlDataQueue" has incompatible type "ResponseHandler | None"; expected "BaseProtocol"  [arg-type]
aiodocker/stream.py:92: error: Item "None" of "ResponseHandler | None" has no attribute "set_parser"  [union-attr]
aiodocker/stream.py:93: error: Item "None" of "ResponseHandler | None" has no attribute "force_close"  [union-attr]
aiodocker/stream.py:94: error: Incompatible types in assignment (expression has type "FlowControlDataQueue[Message]", variable has type "None")  [assignment]
aiodocker/stream.py:111: error: Item "None" of "Connection | None" has no attribute "transport"  [union-attr]
aiodocker/stream.py:112: error: Item "None" of "Transport | Any | None" has no attribute "write"  [union-attr]
aiodocker/stream.py:113: error: Item "None" of "Connection | None" has no attribute "protocol"  [union-attr]
aiodocker/stream.py:114: error: Item "None" of "ResponseHandler | Any | None" has no attribute "transport"  [union-attr]
aiodocker/stream.py:115: error: Item "None" of "ResponseHandler | Any | None" has no attribute "_drain_helper"  [union-attr]
aiodocker/stream.py:123: error: Item "None" of "Connection | None" has no attribute "transport"  [union-attr]
aiodocker/logs.py:44: error: Incompatible types in assignment (expression has type "ClientResponse", variable has type "None")  [assignment]
aiodocker/docker.py:134: error: Argument "ssl" to "TCPConnector" has incompatible type "SSLContext | None"; expected "bool | Fingerprint | SSLContext"  [arg-type]
Found 14 errors in 3 files (checked 39 source files)