@overload with multiple Generic[Any]
#2157
Unanswered
randolf-scholz
asked this question in
Q&A
Replies: 1 comment
-
|
The alternative of not preserving from typing import Any, overload, assert_type
class A[T]: # covariant
def get(self) -> T: ...
@overload
def op(l: A[None], r: A[None]) -> A[None]: ...
@overload
def op(l: A[None], r: A[Any]) -> A[Any]: ...
@overload
def op(l: A[Any], r: A[None]) -> A[Any]: ...
@overload
def op(l: A[Any], r: A[Any]) -> A[Any]: ...
def op(l, r):
# dummy implementation:
if l.get() is None or r.get() is None:
return A[None]()
return A[Any]()
def test(x: A[None], y: A[Any]) -> None:
assert_type(op(x, x), A[None])
assert_type(op(x, y), A[Any]) # ❌️: (pyright, pyrefly, ty)
assert_type(op(y, x), A[Any]) # ❌️: (pyright, pyrefly, ty)
assert_type(op(y, y), A[Any]) # ❌️: (pyright, pyrefly, ty) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Am I missing something, or is it impossible to annotate
opin a way that satisfies theassert_typetest-suite in the example below?The schema is relevant for type hinting numeric types that interact with
math.nan/ nullable values.Beta Was this translation helpful? Give feedback.
All reactions