8000 PEP 604: Remove some more uses of Union/Optional by JelleZijlstra · Pull Request #7515 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

PEP 604: Remove some more uses of Union/Optional #7515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
PEP 604: Remove some more uses of Union
Mypy seems fine with these. Aliases that use type[] or variadic tuple[]
still break mypy.
  • Loading branch information
JelleZijlstra committed Mar 19, 2022
commit 9e5c9feabed12c171c52d75e88dc072b6cffbc1e
4 changes: 2 additions & 2 deletions stdlib/asyncio/trsock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import socket
import sys
from builtins import type as Type # alias to avoid name clashes with property named "type"
from types import TracebackType
from typing import Any, BinaryIO, Iterable, NoReturn, Union, overload
from typing import Any, BinaryIO, Iterable, NoReturn, overload

# These are based in socket, maybe move them out into _typeshed.pyi or such
_Address = Union[tuple[Any, ...], str]
_Address = tuple[Any, ...] | str
_RetAddress = Any
_WriteBuffer = bytearray | memoryview
_CMSG = tuple[int, int, bytes]
Expand Down
23 changes: 10 additions & 13 deletions stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ from typing import (
Protocol,
Sequence,
TypeVar,
Union,
overload,
runtime_checkable,
)
Expand Down Expand Up @@ -388,7 +387,6 @@ _FdOrAnyPath = int | StrOrBytesPath
class DirEntry(Generic[AnyStr]):
# This is what the scandir iterator yields
# The constructor is hidden

@property
def name(self) -> AnyStr: ...
@property
Expand Down Expand Up @@ -832,16 +830,16 @@ def execlpe(file: StrOrBytesPath, __arg0: StrOrBytesPath, *args: Any) -> NoRetur
# Not separating out PathLike[str] and PathLike[bytes] here because it doesn't make much difference
# in practice, and doing so would explode the number of combinations in this already long union.
# All these combinations are necessary due to list being invariant.
_ExecVArgs = Union[
tuple[StrOrBytesPath, ...],
list[bytes],
list[str],
list[PathLike[Any]],
list[bytes | str],
list[bytes | PathLike[Any]],
list[str | PathLike[Any]],
list[bytes | str | PathLike[Any]],
]
_ExecVArgs = (
tuple[StrOrBytesPath, ...]
| list[bytes]
| list[str]
| list[PathLike[Any]]
| list[bytes | str]
| list[bytes | PathLike[Any]]
| list[str | PathLike[Any]]
| list[bytes | str | PathLike[Any]]
)
_ExecEnv = Mapping[bytes, bytes | str] | Mapping[str, bytes | str]

def execv(__path: StrOrBytesPath, __argv: _ExecVArgs) -> NoReturn: ...
Expand Down Expand Up @@ -1034,6 +1032,5 @@ if sys.version_info >= (3, 8):

if sys.version_info >= (3, 9):
def waitstatus_to_exitcode(status: int) -> int: ...

if sys.platform == "linux":
def pidfd_open(pid: int, 10000 flags: int = ...) -> int: ...
4 changes: 2 additions & 2 deletions stdlib/signal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sys
from _typeshed import structseq
from enum import IntEnum
from types import FrameType
from typing import Any, Callable, Iterable, Union
from typing import Any, Callable, Iterable
from typing_extensions import final

NSIG: int
Expand Down Expand Up @@ -61,7 +61,7 @@ SIG_DFL: Handlers
SIG_IGN: Handlers

_SIGNUM = int | Signals
_HANDLER = Union[Callable[[int, FrameType | None], Any], int, Handlers, None]
_HANDLER = Callable[[int, FrameType | None], Any] | int | Handlers | None

def default_int_handler(__signalnum: int, __frame: FrameType | None) -> None: ...

Expand Down
4 changes: 2 additions & 2 deletions stdlib/ssl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import enum
import socket
import sys
from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer
from typing import Any, Callable, Iterable, NamedTuple, Union, overload
from typing import Any, Callable, Iterable, NamedTuple, overload
from typing_extensions import Literal, TypedDict, final

_PCTRTT = tuple[tuple[str, str], ...]
_PCTRTTT = tuple[_PCTRTT, ...]
_PeerCertRetDictType = dict[str, str | _PCTRTTT | _PCTRTT]
_PeerCertRetType = _PeerCertRetDictType | bytes | None
_EnumRetType = list[tuple[bytes, str, set[str] | bool]]
_PasswordType = Union[Callable[[], str | bytes], str, bytes]
_PasswordType = Callable[[], str | bytes] | str | bytes

_SrvnmeCbType = Callable[[SSLSocket | SSLObject, str | None, SSLSocket], int | None]

Expand Down
8 changes: 5 additions & 3 deletions stdlib/xmlrpc/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class _SupportsTimeTuple(Protocol):
def timetuple(self) -> time.struct_time: ...

_DateTimeComparable = DateTime | datetime | str | _SupportsTimeTuple
_Marshallable = Union[None, bool, int, float, str, bytes, tuple[Any, ...], list[Any], dict[Any, Any], datetime, DateTime, Binary]
_XMLDate = Union[int, datetime, tuple[int, ...], time.struct_time]
_HostType = Union[tuple[str, dict[str, str]], str]
_Marshallable = (
bool | int | float | str | bytes | None | tuple[Any, ...] | list[Any] | dict[Any, Any] | datetime | DateTime | Binary
)
_XMLDate = int | datetime | tuple[int, ...] | time.struct_time
_HostType = Union[str, tuple[str, dict[str, str]]]

def escape(s: str) -> str: ... # undocumented

Expand Down
2 changes: 1 addition & 1 deletion stubs/requests/requests/sessions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SessionRedirectMixin:
def rebuild_proxies(self, prepared_request, proxies): ...
def should_strip_auth(self, old_url, new_url): ...

_Data = Union[None, Text, bytes, Mapping[str, Any], Mapping[Text, Any], Iterable[tuple[Text, Optional[Text]]], IO[Any]]
_Data = Text | bytes | Mapping[str, Any] | Mapping[Text, Any] | Iterable[tuple[Text, Optional[Text]]] | IO[Any] | None

_Hook = Callable[[Response], Any]
_Hooks = MutableMapping[Text, _Hook | list[_Hook]]
Expand Down
0