Replace Literal[None] with None in typing (#163489)

This PR replaces Literal[None] with None in typing.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/163489
Approved by: https://github.com/Skylion007, https://github.com/mlazos
This commit is contained in:
Yuanyuan Chen
2025-09-22 22:10:05 +00:00
committed by PyTorch MergeBot
parent b756b580fb
commit 60c2bdedcd
6 changed files with 10 additions and 19 deletions

View File

@ -4,7 +4,7 @@ circular dependencies.
"""
import functools
from typing import Callable, Literal, Optional, overload, TypeVar, Union
from typing import Callable, Optional, overload, TypeVar, Union
from typing_extensions import ParamSpec
@ -20,7 +20,7 @@ def _disable_dynamo(
@overload
def _disable_dynamo(
fn: Literal[None] = None, recursive: bool = True
fn: None = None, recursive: bool = True
) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ...

View File

@ -1116,7 +1116,7 @@ class cpp:
simdlen: Optional[int] = None
min_chunk_size = int(os.environ.get("TORCHINDUCTOR_CPP_MIN_CHUNK_SIZE", "512"))
cxx: tuple[Literal[None], str] = (
cxx: tuple[None, str] = (
None, # download gcc12 from conda-forge if conda is installed
os.environ.get("CXX", "clang++" if sys.platform == "darwin" else "g++"),
) # type: ignore[assignment]

View File

@ -352,7 +352,7 @@ def get_stride_order(
@overload
def ir_node_to_tensor(x: Literal[None], guard_shape: bool = True) -> None: ...
def ir_node_to_tensor(x: None, guard_shape: bool = True) -> None: ...
@overload

View File

@ -5,7 +5,7 @@ import logging
import weakref
from collections.abc import Iterable, Sequence
from contextlib import contextmanager
from typing import Any, Callable, Literal, Optional, overload, Union
from typing import Any, Callable, Optional, overload, Union
import torch
from torch import _C, _ops, Tensor
@ -22,7 +22,7 @@ log = logging.getLogger(__name__)
@overload
def custom_op(
name: str,
fn: Literal[None] = None,
fn: None = None,
/,
*,
mutates_args: Union[str, Iterable[str]],

View File

@ -862,7 +862,7 @@ def _record_memory_history_legacy(
def _record_memory_history(
enabled: Literal[None, "state", "all"] = "all", *args, **kwargs
enabled: Optional[Literal["state", "all"]] = "all", *args, **kwargs
) -> None:
"""Enable recording of stack traces associated with memory
allocations, so you can tell what allocated any piece of memory in

View File

@ -7,16 +7,7 @@ import sys
import traceback
import weakref
from collections.abc import Sequence
from typing import (
Any,
Callable,
Literal,
Optional,
overload,
TYPE_CHECKING,
TypeVar,
Union,
)
from typing import Any, Callable, Optional, overload, TYPE_CHECKING, TypeVar, Union
from typing_extensions import deprecated, ParamSpec
import torch
@ -562,7 +553,7 @@ def _(lib: Library, schema, alias_analysis=""):
def impl(
qualname: str,
types: Union[str, Sequence[str]],
func: Literal[None] = None,
func: None = None,
*,
lib: Optional[Library] = None,
) -> Callable[[Callable[..., object]], None]: ...
@ -674,7 +665,7 @@ if not TYPE_CHECKING:
def _impl(
qualname: str,
types: Union[str, Sequence[str]],
func: Literal[None] = None,
func: None = None,
*,
lib: Optional[Library] = None,
disable_dynamo: bool = False,