Replies: 1 comment
-
When a type checker evaluates the type of a call expression, it first evaluates the type of the call (in this case, from typing import Iterable
def func1[T](i: Iterable[T]) -> set[T]:
return set(i)
def func2(val: tuple[int, ...] | tuple[str, ...]):
reveal_type(func1(val)) # set[int | str] When evaluating the type of the call expression |
Beta Was this translation helpful? Give feedback.
-
I was curious, when converting a unioned tuple into another collection type, such as
list
orset
, you end up with something likeset[int | str]
as opposed toset[int] | set[str]
Is there a particular reason why this is the case? The later seems like it would be more accurate. For what it's worth, I don't see any other type-checkers handling this better than Pyright does, but had a case where I had to (what felt pointlessly) break out narrowing into different cases to work around the type-checker with this.
Beta Was this translation helpful? Give feedback.
All reactions