Files
pytorch/torch/utils/_typing_utils.py
Chip Turner 937d616e82 Re-enable type checking for distributed_c10d.py (#115223)
Re-enable type checking for distributed_c10d.py

Type checking for distributed_c10d.py was inadvertently turned off in issues that have accumulated since.

Note: the backwards compatibility linter does not like some of these changes.  But they were incorrect before.  This needs human verification, however.

#suppress-api-compatibility-check

Pull Request resolved: https://github.com/pytorch/pytorch/pull/115223
Approved by: https://github.com/wconstab
2023-12-09 11:07:54 +00:00

14 lines
377 B
Python

"""Miscellaneous utilities to aid with typing."""
from typing import Optional, TypeVar
# Helper to turn Optional[T] into T when we know None either isn't
# possible or should trigger an exception.
T = TypeVar("T")
def not_none(obj: Optional[T]) -> T:
if obj is None:
raise TypeError("Invariant encountered: value was None when it should not be")
return obj