mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
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
14 lines
377 B
Python
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
|