mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
See https://github.com/pytorch/pytorch/pull/129751#issue-2380881501. Most changes are auto-generated by linter. You can review these PRs via: ```bash git diff --ignore-all-space --ignore-blank-lines HEAD~1 ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/129771 Approved by: https://github.com/justinchuby, https://github.com/janeyx99
15 lines
378 B
Python
15 lines
378 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
|