Skip to content
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

Sync typeshed #16009

Merged
merged 5 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class _CData(metaclass=_CDataMeta):
def __buffer__(self, __flags: int) -> memoryview: ...
def __release_buffer__(self, __buffer: memoryview) -> None: ...

class _SimpleCData(Generic[_T], _CData):
class _SimpleCData(_CData, Generic[_T]):
value: _T
# The TypeVar can be unsolved here,
# but we can't use overloads without creating many, many mypy false-positive errors
Expand All @@ -78,7 +78,7 @@ class _SimpleCData(Generic[_T], _CData):
class _CanCastTo(_CData): ...
class _PointerLike(_CanCastTo): ...

class _Pointer(Generic[_CT], _PointerLike, _CData):
class _Pointer(_PointerLike, _CData, Generic[_CT]):
_type_: type[_CT]
contents: _CT
@overload
Expand Down Expand Up @@ -140,7 +140,7 @@ class _StructUnionBase(_CData, metaclass=_StructUnionMeta):
class Union(_StructUnionBase): ...
class Structure(_StructUnionBase): ...

class Array(Generic[_CT], _CData):
class Array(_CData, Generic[_CT]):
@property
@abstractmethod
def _length_(self) -> int: ...
Expand Down
7 changes: 6 additions & 1 deletion mypy/typeshed/stdlib/asyncio/taskgroups.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys
from contextvars import Context
from types import TracebackType
from typing import TypeVar
from typing import Any, TypeVar
from typing_extensions import Self

from . import _CoroutineLike
from .events import AbstractEventLoop
from .tasks import Task

if sys.version_info >= (3, 12):
Expand All @@ -15,6 +16,10 @@ else:
_T = TypeVar("_T")

class TaskGroup:
_loop: AbstractEventLoop | None
_tasks: set[Task[Any]]

async def __aenter__(self) -> Self: ...
async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ...
def create_task(self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None) -> Task[_T]: ...
def _on_task_done(self, task: Task[object]) -> None: ...
30 changes: 21 additions & 9 deletions mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,6 @@ if sys.version_info >= (3, 10):
async def sleep(delay: float) -> None: ...
@overload
async def sleep(delay: float, result: _T) -> _T: ...
@overload
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
@overload
async def wait(
fs: Iterable[Awaitable[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
async def wait_for(fut: _FutureLike[_T], timeout: float | None) -> _T: ...

else:
Expand All @@ -257,6 +251,25 @@ else:
async def sleep(delay: float, *, loop: AbstractEventLoop | None = None) -> None: ...
@overload
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = None) -> _T: ...
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...

if sys.version_info >= (3, 11):
@overload
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
@overload
async def wait(
fs: Iterable[Task[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...

elif sys.version_info >= (3, 10):
@overload
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
@overload
async def wait(
fs: Iterable[Awaitable[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...

else:
@overload
async def wait( # type: ignore[misc]
fs: Iterable[_FT],
Expand All @@ -273,7 +286,6 @@ else:
timeout: float | None = None,
return_when: str = "ALL_COMPLETED",
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...

if sys.version_info >= (3, 12):
_TaskCompatibleCoro: TypeAlias = Coroutine[Any, Any, _T_co]
Expand All @@ -291,7 +303,7 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
name: str | None,
name: str | None = ...,
context: Context | None = None,
eager_start: bool = False,
) -> None: ...
Expand All @@ -301,7 +313,7 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
name: str | None,
name: str | None = ...,
context: Context | None = None,
) -> None: ...
elif sys.version_info >= (3, 8):
Expand Down
81 changes: 54 additions & 27 deletions mypy/typeshed/stdlib/configparser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,53 @@ from re import Pattern
from typing import Any, ClassVar, TypeVar, overload
from typing_extensions import Literal, TypeAlias

__all__ = [
"NoSectionError",
"DuplicateOptionError",
"DuplicateSectionError",
"NoOptionError",
"InterpolationError",
"InterpolationDepthError",
"InterpolationMissingOptionError",
"InterpolationSyntaxError",
"ParsingError",
"MissingSectionHeaderError",
"ConfigParser",
"RawConfigParser",
"Interpolation",
"BasicInterpolation",
"ExtendedInterpolation",
"LegacyInterpolation",
"SectionProxy",
"ConverterMapping",
"DEFAULTSECT",
"MAX_INTERPOLATION_DEPTH",
]

if sys.version_info < (3, 12):
__all__ += ["SafeConfigParser"]
if sys.version_info >= (3, 12):
__all__ = (
"NoSectionError",
"DuplicateOptionError",
"DuplicateSectionError",
"NoOptionError",
"InterpolationError",
"InterpolationDepthError",
"InterpolationMissingOptionError",
"InterpolationSyntaxError",
"ParsingError",
"MissingSectionHeaderError",
"ConfigParser",
"RawConfigParser",
"Interpolation",
"BasicInterpolation",
"ExtendedInterpolation",
"LegacyInterpolation",
"SectionProxy",
"ConverterMapping",
"DEFAULTSECT",
"MAX_INTERPOLATION_DEPTH",
)
else:
__all__ = [
"NoSectionError",
"DuplicateOptionError",
"DuplicateSectionError",
"NoOptionError",
"InterpolationError",
"InterpolationDepthError",
"InterpolationMissingOptionError",
"InterpolationSyntaxError",
"ParsingError",
"MissingSectionHeaderError",
"ConfigParser",
"SafeConfigParser",
"RawConfigParser",
"Interpolation",
"BasicInterpolation",
"ExtendedInterpolation",
"LegacyInterpolation",
"SectionProxy",
"ConverterMapping",
"DEFAULTSECT",
"MAX_INTERPOLATION_DEPTH",
]

_Section: TypeAlias = Mapping[str, str]
_Parser: TypeAlias = MutableMapping[str, _Section]
Expand Down Expand Up @@ -128,7 +150,8 @@ class RawConfigParser(_Parser):
def read_file(self, f: Iterable[str], source: str | None = None) -> None: ...
def read_string(self, string: str, source: str = "<string>") -> None: ...
def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = "<dict>") -> None: ...
def readfp(self, fp: Iterable[str], filename: str | None = None) -> None: ...
if sys.version_info < (3, 12):
def readfp(self, fp: Iterable[str], filename: str | None = None) -> None: ...
# These get* methods are partially applied (with the same names) in
# SectionProxy; the stubs should be kept updated together
@overload
Expand Down Expand Up @@ -277,7 +300,11 @@ class InterpolationSyntaxError(InterpolationError): ...
class ParsingError(Error):
source: str
errors: list[tuple[int, str]]
def __init__(self, source: str | None = None, filename: str | None = None) -> None: ...
if sys.version_info >= (3, 12):
def __init__(self, source: str) -> None: ...
else:
def __init__(self, source: str | None = None, filename: str | None = None) -> None: ...

def append(self, lineno: int, line: str) -> None: ...

class MissingSectionHeaderError(ParsingError):
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class excel(Dialect): ...
class excel_tab(excel): ...
class unix_dialect(Dialect): ...

class DictReader(Generic[_T], Iterator[_DictReadMapping[_T | Any, str | Any]]):
class DictReader(Iterator[_DictReadMapping[_T | Any, str | Any]], Generic[_T]):
fieldnames: Sequence[_T] | None
restkey: str | None
restval: str | None
Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if sys.version_info >= (3, 11):
"verify",
]

if sys.version_info >= (3, 12):
if sys.version_info >= (3, 11):
__all__ += ["pickle_by_enum_name", "pickle_by_global_name"]

_EnumMemberT = TypeVar("_EnumMemberT")
Expand Down Expand Up @@ -188,7 +188,7 @@ class Enum(metaclass=EnumMeta):
def __hash__(self) -> int: ...
def __format__(self, format_spec: str) -> str: ...
def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ...
if sys.version_info >= (3, 12):
if sys.version_info >= (3, 11):
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: Any) -> Self: ...

Expand Down Expand Up @@ -294,6 +294,6 @@ class auto(IntFlag):
def value(self) -> Any: ...
def __new__(cls) -> Self: ...

if sys.version_info >= (3, 12):
if sys.version_info >= (3, 11):
def pickle_by_global_name(self: Enum, proto: int) -> str: ...
def pickle_by_enum_name(self: _EnumMemberT, proto: int) -> tuple[Callable[..., Any], tuple[type[_EnumMemberT], str]]: ...
8 changes: 7 additions & 1 deletion mypy/typeshed/stdlib/genericpath.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from _typeshed import BytesPath, FileDescriptorOrPath, StrPath, SupportsRichComparisonT
import sys
from _typeshed import BytesPath, FileDescriptorOrPath, StrOrBytesPath, StrPath, SupportsRichComparisonT
from collections.abc import Sequence
from typing import overload
from typing_extensions import Literal, LiteralString
Expand All @@ -17,6 +18,8 @@ __all__ = [
"sameopenfile",
"samestat",
]
if sys.version_info >= (3, 12):
__all__ += ["islink"]

# All overloads can return empty string. Ideally, Literal[""] would be a valid
# Iterable[T], so that list[T] | Literal[""] could be used as a return
Expand All @@ -36,6 +39,9 @@ def getsize(filename: FileDescriptorOrPath) -> int: ...
def isfile(path: FileDescriptorOrPath) -> bool: ...
def isdir(s: FileDescriptorOrPath) -> bool: ...

if sys.version_info >= (3, 12):
def islink(path: StrOrBytesPath) -> bool: ...

# These return float if os.stat_float_times() == True,
# but int is a subclass of float.
def getatime(filename: FileDescriptorOrPath) -> float: ...
Expand Down
6 changes: 4 additions & 2 deletions mypy/typeshed/stdlib/gzip.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ class GzipFile(_compression.BaseStream):
fileobj: _ReadableFileobj | _WritableFileobj | None = None,
mtime: float | None = None,
) -> None: ...
@property
def filename(self) -> str: ...
if sys.version_info < (3, 12):
@property
def filename(self) -> str: ...

@property
def mtime(self) -> int | None: ...
crc: int
Expand Down
5 changes: 5 additions & 0 deletions mypy/typeshed/stdlib/ntpath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ from posixpath import (
splitext as splitext,
supports_unicode_filenames as supports_unicode_filenames,
)

if sys.version_info >= (3, 12):
from posixpath import isjunction as isjunction, splitroot as splitroot
from typing import AnyStr, overload
from typing_extensions import LiteralString

Expand Down Expand Up @@ -85,6 +88,8 @@ __all__ = [
"samestat",
"commonpath",
]
if sys.version_info >= (3, 12):
__all__ += ["isjunction", "splitroot"]

altsep: LiteralString

Expand Down
9 changes: 8 additions & 1 deletion mypy/typeshed/stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ class DirEntry(Generic[AnyStr]):
def __fspath__(self) -> AnyStr: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
if sys.version_info >= (3, 12):
def is_junction(self) -> bool: ...

@final
class statvfs_result(structseq[int], tuple[int, int, int, int, int, int, int, int, int, int, int]):
Expand Down Expand Up @@ -602,7 +604,12 @@ def isatty(__fd: int) -> bool: ...
if sys.platform != "win32" and sys.version_info >= (3, 11):
def login_tty(__fd: int) -> None: ...

def lseek(__fd: int, __position: int, __how: int) -> int: ...
if sys.version_info >= (3, 11):
def lseek(__fd: int, __position: int, __whence: int) -> int: ...

else:
def lseek(__fd: int, __position: int, __how: int) -> int: ...

def open(path: StrOrBytesPath, flags: int, mode: int = 0o777, *, dir_fd: int | None = None) -> int: ...
def pipe() -> tuple[int, int]: ...
def read(__fd: int, __length: int) -> bytes: ...
Expand Down
9 changes: 9 additions & 0 deletions mypy/typeshed/stdlib/posixpath.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ __all__ = [
"relpath",
"commonpath",
]
if sys.version_info >= (3, 12):
__all__ += ["isjunction", "splitroot"]

supports_unicode_filenames: bool
# aliases (also in os)
Expand Down Expand Up @@ -150,3 +152,10 @@ def isabs(s: StrOrBytesPath) -> bool: ...
def islink(path: FileDescriptorOrPath) -> bool: ...
def ismount(path: FileDescriptorOrPath) -> bool: ...
def lexists(path: FileDescriptorOrPath) -> bool: ...

if sys.version_info >= (3, 12):
def isjunction(path: StrOrBytesPath) -> bool: ...
@overload
def splitroot(p: AnyOrLiteralStr) -> tuple[AnyOrLiteralStr, AnyOrLiteralStr, AnyOrLiteralStr]: ...
@overload
def splitroot(p: PathLike[AnyStr]) -> tuple[AnyStr, AnyStr, AnyStr]: ...
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/pydoc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def render_doc(
thing: str | object, title: str = "Python Library Documentation: %s", forceload: bool = ..., renderer: Doc | None = None
) -> str: ...

if sys.version_info >= (3, 12):
if sys.version_info >= (3, 11):
def doc(
thing: str | object,
title: str = "Python Library Documentation: %s",
Expand Down Expand Up @@ -230,7 +230,7 @@ class Helper:
def __call__(self, request: str | Helper | object = ...) -> None: ...
def interact(self) -> None: ...
def getline(self, prompt: str) -> str: ...
if sys.version_info >= (3, 12):
if sys.version_info >= (3, 11):
def help(self, request: Any, is_cli: bool = False) -> None: ...
else:
def help(self, request: Any) -> None: ...
Expand Down
Loading