[BE]: Update Typeguard to TypeIs for better type inference (#133814)

Uses TypeIs instead of TypeGuard for better inference. See https://peps.python.org/pep-0742/

Pull Request resolved: https://github.com/pytorch/pytorch/pull/133814
Approved by: https://github.com/ezyang
This commit is contained in:
Aaron Gokaslan
2024-08-20 17:19:55 +00:00
committed by PyTorch MergeBot
parent fbf3fc2a30
commit bce0caba78
9 changed files with 22 additions and 22 deletions

View File

@ -70,7 +70,7 @@ from typing import (
TypeVar,
Union,
)
from typing_extensions import Self, TypeGuard
from typing_extensions import Self, TypeIs
import torch
import torch._guards
@ -277,10 +277,10 @@ class FailedMatch(RuntimeError):
MatchResult = Union[Match, FailedMatch]
def is_match(m: MatchResult) -> TypeGuard[Match]:
def is_match(m: MatchResult) -> TypeIs[Match]:
"""
TypeGuards cannot act on `self`. Thus this function exists to let mypy
recognize FailedMatch.__bool__ as a TypeGuard.
TypeIs cannot act on `self`. Thus this function exists to let mypy
recognize FailedMatch.__bool__ as a TypeIs.
"""
return bool(m)