Confusion about passing tuple-type values to the timeout parameter of the Timeout class
#3779
Replies: 2 comments
|
You are not misreading the implementation: the runtime behavior and the public type alias disagree. On current I reproduced the mismatch on that commit: Until the annotation is aligned, the typed equivalent is: timeout = httpx.Timeout(
connect=10.0,
read=30.0,
write=None,
pool=None,
)or: timeout = httpx.Timeout((10.0, 30.0, None, None))If 2- and 3-item tuples are intended to remain supported, Update: I prepared the minimal type-alias change and runtime coverage in a signed commit: encode:b5addb6...SirHegel:2fb3342 It passes |
|
On top of the stub mismatch already called out: don't pass a bare tuple into import httpx
timeout = httpx.Timeout(10.0, connect=5.0)
timeout = httpx.Timeout(None, connect=5.0, read=30.0)
client = httpx.Client(timeout=httpx.Timeout(10.0, connect=5.0))One float still means "same value for every phase": httpx.Timeout(10.0)Runtime historically accepted a 2 to 4 length tuple and mapped positions to connect/read/write/pool. The published types didn't keep up, so mypy rejects Keywords are clearer anyway and type-check today. |
Uh oh!
There was an error while loading. Please reload this page.
In this code section, it appears that the
timeoutparameter can accept a tuple of length 2 to 4. However, when I do this, the type system reports an error.Reproduction steps:
test_httpx_timeout.pymypy test_httpx_timeout.pyand I get the following error:All reactions