mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[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:
committed by
PyTorch MergeBot
parent
fbf3fc2a30
commit
bce0caba78
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user