Closed irgolic closed 3 days ago
I encountered a similar issue, there seem to be a bug with TypeIs[type[...]]
: considering the guard
def is_str_type(typ: Any) -> TypeIs[type[str]]:
return typ is str
the following works as expected:
def test_simple(typ: type[Any], val: Any) -> None:
if is_str_type(typ):
reveal_type(typ) # Type of "typ" is "type[str]"
but not when using a type variable (PEP 695 style or not):
def test_typevar[T](typ: type[T], val: T) -> None:
if is_str_type(typ):
reveal_type(typ) # Type of "typ" is "Never"
FTR, it works as expected using a TypeGuard instead (playground), or using mypy (playground).
I'm not 100% sure it is the same issue; I can open a new one if necessary.
This is addressed in pyright 1.1.380.
Thank you!
Describe the bug Not sure how wide this bug is, but my
Sentinel
type used to negate types fine in experimental StrictTypeGuard back on 347. On 375 I'm assuming that behavior was disabled for sake of TypeIs, which doesn't work correctly for my case.Also note the weird
UnionType
that appears, and obstructs the use of that object without casting it to what it's supposed to be.Code or Screenshots
VS Code extension or command-line Running CLI,
pyright 1.1.375