Repository navigation
Replies: 1 comment
|
Yes, For example, a type checker can preserve the union at the call site: from typing import assert_type
a: Cache[int] = Cache([1])
b: Cache[str] = Cache(["x"])
assert_type(combine(a, b), Cache[int | str])I checked the example with Python 3.12 and mypy 2.3.1. |
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.
I'm trying to combine two
Cacheinstances with different element types and preserve both types in the result.Is
Cache[T | U]the correct return type here, or is there a better way to type this?What I'd like to avoid is losing type information or having to use
Anyorcast.All reactions