Skip to content

Commit

Permalink
Sync typeshed (#17124)
Browse files Browse the repository at this point in the history
Source commit:

python/typeshed@7c8e82f

Co-authored-by: mypybot <>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent e2fc1f2 commit 5161ac2
Show file tree
Hide file tree
Showing 17 changed files with 795 additions and 730 deletions.
1,091 changes: 549 additions & 542 deletions mypy/typeshed/stdlib/_curses.pyi

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions mypy/typeshed/stdlib/asyncio/streams.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ssl
import sys
from _typeshed import StrPath
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence
from typing import Any, SupportsIndex
from _typeshed import ReadableBuffer, StrPath
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence, Sized
from typing import Any, Protocol, SupportsIndex
from typing_extensions import Self, TypeAlias

from . import events, protocols, transports
Expand All @@ -23,6 +23,8 @@ else:

_ClientConnectedCallback: TypeAlias = Callable[[StreamReader, StreamWriter], Awaitable[None] | None]

class _ReaduntilBuffer(ReadableBuffer, Sized, Protocol): ...

if sys.version_info >= (3, 10):
async def open_connection(
host: str | None = None,
Expand Down Expand Up @@ -140,8 +142,11 @@ class StreamReader(AsyncIterator[bytes]):
def at_eof(self) -> bool: ...
def feed_data(self, data: Iterable[SupportsIndex]) -> None: ...
async def readline(self) -> bytes: ...
# Can be any buffer that supports len(); consider changing to a Protocol if PEP 688 is accepted
async def readuntil(self, separator: bytes | bytearray | memoryview = b"\n") -> bytes: ...
if sys.version_info >= (3, 13):
async def readuntil(self, separator: _ReaduntilBuffer | tuple[_ReaduntilBuffer, ...] = b"\n") -> bytes: ...
else:
async def readuntil(self, separator: _ReaduntilBuffer = b"\n") -> bytes: ...

async def read(self, n: int = -1) -> bytes: ...
async def readexactly(self, n: int) -> bytes: ...
def __aiter__(self) -> Self: ...
Expand Down
27 changes: 14 additions & 13 deletions mypy/typeshed/stdlib/curses/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import sys
from _curses import *
from _curses import _CursesWindow as _CursesWindow
from collections.abc import Callable
from typing import TypeVar
from typing_extensions import Concatenate, ParamSpec

if sys.platform != "win32":
from _curses import *
from _curses import _CursesWindow as _CursesWindow
# NOTE: The _curses module is ordinarily only available on Unix, but the
# windows-curses package makes it available on Windows as well with the same
# contents.

_T = TypeVar("_T")
_P = ParamSpec("_P")
_T = TypeVar("_T")
_P = ParamSpec("_P")

# available after calling `curses.initscr()`
LINES: int
COLS: int
# available after calling `curses.initscr()`
LINES: int
COLS: int

# available after calling `curses.start_color()`
COLORS: int
COLOR_PAIRS: int
# available after calling `curses.start_color()`
COLORS: int
COLOR_PAIRS: int

def wrapper(func: Callable[Concatenate[_CursesWindow, _P], _T], /, *arg: _P.args, **kwds: _P.kwargs) -> _T: ...
def wrapper(func: Callable[Concatenate[_CursesWindow, _P], _T], /, *arg: _P.args, **kwds: _P.kwargs) -> _T: ...
117 changes: 58 additions & 59 deletions mypy/typeshed/stdlib/curses/ascii.pyi
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
import sys
from typing import TypeVar

if sys.platform != "win32":
_CharT = TypeVar("_CharT", str, int)
_CharT = TypeVar("_CharT", str, int)

NUL: int
SOH: int
STX: int
ETX: int
EOT: int
ENQ: int
ACK: int
BEL: int
BS: int
TAB: int
HT: int
LF: int
NL: int
VT: int
FF: int
CR: int
SO: int
SI: int
DLE: int
DC1: int
DC2: int
DC3: int
DC4: int
NAK: int
SYN: int
ETB: int
CAN: int
EM: int
SUB: int
ESC: int
FS: int
GS: int
RS: int
US: int
SP: int
DEL: int
NUL: int
SOH: int
STX: int
ETX: int
EOT: int
ENQ: int
ACK: int
BEL: int
BS: int
TAB: int
HT: int
LF: int
NL: int
VT: int
FF: int
CR: int
SO: int
SI: int
DLE: int
DC1: int
DC2: int
DC3: int
DC4: int
NAK: int
SYN: int
ETB: int
CAN: int
EM: int
SUB: int
ESC: int
FS: int
GS: int
RS: int
US: int
SP: int
DEL: int

controlnames: list[int]
def isalnum(c: str | int) -> bool: ...
def isalpha(c: str | int) -> bool: ...
def isascii(c: str | int) -> bool: ...
def isblank(c: str | int) -> bool: ...
def iscntrl(c: str | int) -> bool: ...
def isdigit(c: str | int) -> bool: ...
def isgraph(c: str | int) -> bool: ...
def islower(c: str | int) -> bool: ...
def isprint(c: str | int) -> bool: ...
def ispunct(c: str | int) -> bool: ...
def isspace(c: str | int) -> bool: ...
def isupper(c: str | int) -> bool: ...
def isxdigit(c: str | int) -> bool: ...
def isctrl(c: str | int) -> bool: ...
def ismeta(c: str | int) -> bool: ...
def ascii(c: _CharT) -> _CharT: ...
def ctrl(c: _CharT) -> _CharT: ...
def alt(c: _CharT) -> _CharT: ...
def unctrl(c: str | int) -> str: ...
controlnames: list[int]

def isalnum(c: str | int) -> bool: ...
def isalpha(c: str | int) -> bool: ...
def isascii(c: str | int) -> bool: ...
def isblank(c: str | int) -> bool: ...
def iscntrl(c: str | int) -> bool: ...
def isdigit(c: str | int) -> bool: ...
def isgraph(c: str | int) -> bool: ...
def islower(c: str | int) -> bool: ...
def isprint(c: str | int) -> bool: ...
def ispunct(c: str | int) -> bool: ...
def isspace(c: str | int) -> bool: ...
def isupper(c: str | int) -> bool: ...
def isxdigit(c: str | int) -> bool: ...
def isctrl(c: str | int) -> bool: ...
def ismeta(c: str | int) -> bool: ...
def ascii(c: _CharT) -> _CharT: ...
def ctrl(c: _CharT) -> _CharT: ...
def alt(c: _CharT) -> _CharT: ...
def unctrl(c: str | int) -> str: ...
5 changes: 1 addition & 4 deletions mypy/typeshed/stdlib/curses/has_key.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import sys

if sys.platform != "win32":
def has_key(ch: int | str) -> bool: ...
def has_key(ch: int | str) -> bool: ...
41 changes: 19 additions & 22 deletions mypy/typeshed/stdlib/curses/panel.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import sys
from _curses import _CursesWindow

if sys.platform != "win32":
from _curses import _CursesWindow
version: str

version: str
class _Curses_Panel: # type is <class '_curses_panel.curses panel'> (note the space in the class name)
def above(self) -> _Curses_Panel: ...
def below(self) -> _Curses_Panel: ...
def bottom(self) -> None: ...
def hidden(self) -> bool: ...
def hide(self) -> None: ...
def move(self, y: int, x: int) -> None: ...
def replace(self, win: _CursesWindow) -> None: ...
def set_userptr(self, obj: object) -> None: ...
def show(self) -> None: ...
def top(self) -> None: ...
def userptr(self) -> object: ...
def window(self) -> _CursesWindow: ...

class _Curses_Panel: # type is <class '_curses_panel.curses panel'> (note the space in the class name)
def above(self) -> _Curses_Panel: ...
def below(self) -> _Curses_Panel: ...
def bottom(self) -> None: ...
def hidden(self) -> bool: ...
def hide(self) -> None: ...
def move(self, y: int, x: int) -> None: ...
def replace(self, win: _CursesWindow) -> None: ...
def set_userptr(self, obj: object) -> None: ...
def show(self) -> None: ...
def top(self) -> None: ...
def userptr(self) -> object: ...
def window(self) -> _CursesWindow: ...

def bottom_panel() -> _Curses_Panel: ...
def new_panel(win: _CursesWindow, /) -> _Curses_Panel: ...
def top_panel() -> _Curses_Panel: ...
def update_panels() -> _Curses_Panel: ...
def bottom_panel() -> _Curses_Panel: ...
def new_panel(win: _CursesWindow, /) -> _Curses_Panel: ...
def top_panel() -> _Curses_Panel: ...
def update_panels() -> _Curses_Panel: ...
18 changes: 8 additions & 10 deletions mypy/typeshed/stdlib/curses/textpad.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import sys
from _curses import _CursesWindow
from collections.abc import Callable

if sys.platform != "win32":
from _curses import _CursesWindow
def rectangle(win: _CursesWindow, uly: int, ulx: int, lry: int, lrx: int) -> None: ...
def rectangle(win: _CursesWindow, uly: int, ulx: int, lry: int, lrx: int) -> None: ...

class Textbox:
stripspaces: bool
def __init__(self, win: _CursesWindow, insert_mode: bool = False) -> None: ...
def edit(self, validate: Callable[[int], int] | None = None) -> str: ...
def do_command(self, ch: str | int) -> None: ...
def gather(self) -> str: ...
class Textbox:
stripspaces: bool
def __init__(self, win: _CursesWindow, insert_mode: bool = False) -> None: ...
def edit(self, validate: Callable[[int], int] | None = None) -> str: ...
def do_command(self, ch: str | int) -> None: ...
def gather(self) -> str: ...
15 changes: 11 additions & 4 deletions mypy/typeshed/stdlib/importlib/resources/simple.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import abc
import sys
from _typeshed import Incomplete, OpenBinaryMode, OpenTextMode, Unused
from collections.abc import Iterator
from io import TextIOWrapper
from typing import IO, Any, BinaryIO, Literal, NoReturn, overload
Expand Down Expand Up @@ -28,11 +27,19 @@ if sys.version_info >= (3, 11):
def is_file(self) -> Literal[True]: ...
def is_dir(self) -> Literal[False]: ...
@overload
def open(self, mode: OpenTextMode = "r", *args, **kwargs) -> TextIOWrapper: ...
def open(
self,
mode: Literal["r"] = "r",
encoding: str | None = None,
errors: str | None = None,
newline: str | None = None,
line_buffering: bool = False,
write_through: bool = False,
) -> TextIOWrapper: ...
@overload
def open(self, mode: OpenBinaryMode, *args: Unused, **kwargs: Unused) -> BinaryIO: ...
def open(self, mode: Literal["rb"]) -> BinaryIO: ...
@overload
def open(self, mode: str, *args: Incomplete, **kwargs) -> IO[Any]: ...
def open(self, mode: str) -> IO[Any]: ...
def joinpath(self, name: Never) -> NoReturn: ... # type: ignore[override]

class ResourceContainer(Traversable, metaclass=abc.ABCMeta):
Expand Down
10 changes: 5 additions & 5 deletions mypy/typeshed/stdlib/io.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ class TextIOWrapper(TextIOBase, TextIO): # type: ignore[misc] # incompatible d
def __init__(
self,
buffer: _WrappedBuffer,
encoding: str | None = ...,
errors: str | None = ...,
newline: str | None = ...,
line_buffering: bool = ...,
write_through: bool = ...,
encoding: str | None = None,
errors: str | None = None,
newline: str | None = None,
line_buffering: bool = False,
write_through: bool = False,
) -> None: ...
# Equals the "buffer" argument passed in to the constructor.
@property
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/multiprocessing/resource_tracker.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ __all__ = ["ensure_running", "register", "unregister"]
class ResourceTracker:
def getfd(self) -> int | None: ...
def ensure_running(self) -> None: ...
def register(self, name: Sized, rtype) -> None: ...
def unregister(self, name: Sized, rtype) -> None: ...
def register(self, name: Sized, rtype: str) -> None: ...
def unregister(self, name: Sized, rtype: str) -> None: ...

_resource_tracker: ResourceTracker
ensure_running = _resource_tracker.ensure_running
Expand Down
31 changes: 25 additions & 6 deletions mypy/typeshed/stdlib/multiprocessing/util.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import threading
from _typeshed import ConvertibleToInt, Incomplete, Unused
from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence
from logging import Logger, _Level as _LoggingLevel
from typing import Any
from typing import Any, Generic, TypeVar, overload

__all__ = [
"sub_debug",
Expand All @@ -22,6 +22,9 @@ __all__ = [
"SUBWARNING",
]

_T = TypeVar("_T")
_R_co = TypeVar("_R_co", default=Any, covariant=True)

NOTSET: int
SUBDEBUG: int
DEBUG: int
Expand All @@ -42,13 +45,29 @@ def is_abstract_socket_namespace(address: str | bytes | None) -> bool: ...
abstract_sockets_supported: bool

def get_temp_dir() -> str: ...
def register_after_fork(obj, func: Callable[[Incomplete], object]) -> None: ...
def register_after_fork(obj: _T, func: Callable[[_T], object]) -> None: ...

class Finalize:
class Finalize(Generic[_R_co]):
# "args" and "kwargs" are passed as arguments to "callback".
@overload
def __init__(
self,
obj: None,
callback: Callable[..., _R_co],
*,
args: Sequence[Any] = (),
kwargs: Mapping[str, Any] | None = None,
exitpriority: int,
) -> None: ...
@overload
def __init__(
self, obj: None, callback: Callable[..., _R_co], args: Sequence[Any], kwargs: Mapping[str, Any] | None, exitpriority: int
) -> None: ...
@overload
def __init__(
self,
obj: Incomplete | None,
callback: Callable[..., Incomplete],
obj: Any,
callback: Callable[..., _R_co],
args: Sequence[Any] = (),
kwargs: Mapping[str, Any] | None = None,
exitpriority: int | None = None,
Expand All @@ -59,7 +78,7 @@ class Finalize:
_finalizer_registry: MutableMapping[Incomplete, Incomplete] = {},
sub_debug: Callable[..., object] = ...,
getpid: Callable[[], int] = ...,
): ...
) -> _R_co: ...
def cancel(self) -> None: ...
def still_active(self) -> bool: ...

Expand Down
Loading

0 comments on commit 5161ac2

Please sign in to comment.