You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The recent httpx-ws release made the result of aconnect_ws generic on the returned session type: frankie567/httpx-ws@dc716cc
Even though the newly introduced generic type variable is a bound type variable (anchored by AsyncWebsocketSession, the previous concrete return type), mypy started complaining that ws in the following code needed a type declaration:
The above reproduces the problem with http-ws. I haven't tried reproducing it with a custom async context manager.
Expected Behavior
I actually would have expected the bound type variable on the generic to keep mypy from complaining in the first place.
Failing that, I definitely expected the explicit predeclaration of ws to work, not have it instead be reinterpreted as Never.
The latter seemed like the much stranger result, hence using it as the issue title.
Actual Behavior
The above code is a slightly simplified version of the actual failing test case. The following errors are from the version of the real test case with ws: AsyncWebSocketSession explicitly declared:
tests/test_sdk_bypass.py:30: error: "Never" has no attribute "send_json" [attr-defined]tests/test_sdk_bypass.py:31: error: "Never" has no attribute "receive_json" [attr-defined]tests/test_sdk_bypass.py:55: error: "Never" has no attribute "send_json" [attr-defined]tests/test_sdk_bypass.py:60: error: "Never" has no attribute "receive_json" [attr-defined]
Your Environment
Mypy version used: 1.13.0
Mypy command-line flags: --strict
Mypy configuration options from mypy.ini (and other config files): defaults
Python version used: Python 3.12
httpx-ws version: 0.7.0
The text was updated successfully, but these errors were encountered:
The root issue here is that mypy does not consider the default argument to session_class (AsyncWebSocketSession) when resolving the type variable AsyncSession. This causes AsyncSession to be inferred as Never in absence of other type information. See #3737 for details and workarounds.
On httpx-ws's side, this could be fixed by adding a default type argument for the type variable, e.g.:
Bug Report
The recent
httpx-ws
release made the result ofaconnect_ws
generic on the returned session type: frankie567/httpx-ws@dc716ccEven though the newly introduced generic type variable is a bound type variable (anchored by
AsyncWebsocketSession
, the previous concrete return type),mypy
started complaining thatws
in the following code needed a type declaration:However, adding that declaration didn't fix the problem:
Instead, it started reporting '"Never" has no attribute "send_json"' and '"Never" has no attribute "receive_json"'
The only version I've found that made mypy happy was to explicitly type the context manager with its old non-generic annotation:
To Reproduce
The above reproduces the problem with
http-ws
. I haven't tried reproducing it with a custom async context manager.Expected Behavior
I actually would have expected the bound type variable on the generic to keep mypy from complaining in the first place.
Failing that, I definitely expected the explicit predeclaration of
ws
to work, not have it instead be reinterpreted asNever
.The latter seemed like the much stranger result, hence using it as the issue title.
Actual Behavior
The above code is a slightly simplified version of the actual failing test case. The following errors are from the version of the real test case with
ws: AsyncWebSocketSession
explicitly declared:Your Environment
--strict
mypy.ini
(and other config files): defaultsThe text was updated successfully, but these errors were encountered: