Skip to content

Commit

Permalink
Merge branch 'main' into select.poll
Browse files Browse the repository at this point in the history
  • Loading branch information
tungol committed Dec 24, 2024
2 parents 015466f + 445858c commit 45ffe17
Show file tree
Hide file tree
Showing 113 changed files with 1,173 additions and 529 deletions.
6 changes: 3 additions & 3 deletions lib/ts_utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def read_metadata(distribution: str) -> StubMetadata:
assert isinstance(tools_settings, dict)
assert tools_settings.keys() <= _KNOWN_METADATA_TOOL_FIELDS.keys(), f"Unrecognised tool for {distribution!r}"
for tool, tk in _KNOWN_METADATA_TOOL_FIELDS.items():
settings_for_tool: object = tools_settings.get(tool, {}) # pyright: ignore[reportUnknownMemberType]
settings_for_tool: object = tools_settings.get(tool, {})
assert isinstance(settings_for_tool, dict)
for key in settings_for_tool:
assert key in tk, f"Unrecognised {tool} key {key!r} for {distribution!r}"
Expand Down Expand Up @@ -311,9 +311,9 @@ def update_metadata(distribution: str, **new_values: object) -> tomlkit.TOMLDocu
data = tomlkit.load(file)
except FileNotFoundError:
raise NoSuchStubError(f"Typeshed has no stubs for {distribution!r}!") from None
data.update(new_values) # pyright: ignore[reportUnknownMemberType] # tomlkit.TOMLDocument.update is partially typed
data.update(new_values)
with path.open("w", encoding="UTF-8") as file:
tomlkit.dump(data, file) # pyright: ignore[reportUnknownMemberType] # tomlkit.dump has partially unknown Mapping type
tomlkit.dump(data, file)
return data


Expand Down
2 changes: 1 addition & 1 deletion lib/ts_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from packaging.requirements import Requirement

try:
from termcolor import colored as colored # pyright: ignore[reportAssignmentType]
from termcolor import colored as colored
except ImportError:

def colored(text: str, color: str | None = None, **kwargs: Any) -> str: # type: ignore[misc]
Expand Down
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Type checkers that we test our stubs against. These should always
# be pinned to a specific version to make failure reproducible.
mypy==1.13.0
mypy==1.14.0
pyright==1.1.389
# pytype can be installed on Windows, but requires building wheels, let's not do that on the CI
pytype==2024.10.11; platform_system != "Windows" and python_version >= "3.10" and python_version < "3.13"
Expand Down
16 changes: 5 additions & 11 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@ _collections_abc.AsyncGenerator.ag_await
_collections_abc.AsyncGenerator.ag_code
_collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
asyncio.__all__
asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them
asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them
builtins.dict.get
collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023
contextlib._GeneratorContextManagerBase.__init__ # skipped in the stubs in favor of its child classes
ctypes.CDLL._FuncPtr # None at class level but initialized in __init__ to this value
ctypes.memmove # CFunctionType
ctypes.memset # CFunctionType
http.client.HTTPConnection.response_class # the actual type at runtime is abc.ABCMeta
importlib.abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility
importlib.abc.MetaPathFinder.find_spec # Not defined on the actual class, but expected to exist.
importlib.abc.PathEntryFinder.find_spec # Not defined on the actual class, but expected to exist.
numbers.Number.__hash__ # typeshed marks this as abstract but code just sets this as None
socketserver.BaseServer.fileno # implemented in derived classes
socketserver.BaseServer.get_request # implemented in derived classes
socketserver.BaseServer.server_bind # implemented in derived classes
ssl.Purpose.__new__ # the multiple inheritance confuses mypy
tarfile.TarFile.errors # errors is initialized for some reason as None even though it really only accepts str
tkinter.simpledialog.[A-Z_]+
tkinter.simpledialog.TclVersion
tkinter.simpledialog.TkVersion
tkinter.Text.count # stubtest somehow thinks that index1 parameter has a default value, but it doesn't in any of the overloads
weakref.WeakKeyDictionary.update
weakref.WeakValueDictionary.update


# ===============================================================
Expand Down Expand Up @@ -319,18 +313,17 @@ csv.Dialect.skipinitialspace

csv.DictReader.__init__ # runtime sig has *args but will error if more than 5 positional args are supplied
csv.DictWriter.__init__ # runtime sig has *args but will error if more than 5 positional args are supplied
_?ctypes.Array.raw # exists but stubtest can't see it; only available if _CT == c_char
_?ctypes.Array._type_ # _type_ is abstract, https://github.com/python/typeshed/pull/6361
_?ctypes.Array._length_ # _length_ is abstract, https://github.com/python/typeshed/pull/6361
_?ctypes.Array.raw # exists but stubtest can't see it; only available if _CT == c_char
ctypes.CDLL._FuncPtr # None at class level but initialized in __init__ to this value
_?ctypes.Structure.__getattr__ # doesn't exist, but makes things easy if we pretend it does
_?ctypes.Union.__getattr__ # doesn't exist, but makes things easy if we pretend it does

# Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__)
# These would ideally be special-cased by type checkers; see https://github.com/python/mypy/issues/2220
_?ctypes.Array.__iter__

dataclasses.field # White lies around defaults

# __all__-related weirdness (see #6523)
email.__all__
email.base64mime
Expand Down Expand Up @@ -395,7 +388,6 @@ multiprocessing.dummy.RLock

# These multiprocessing proxy methods have *args, **kwargs signatures at runtime,
# But have more precise (accurate) signatures in the stub
multiprocessing.managers.BaseListProxy.__imul__
multiprocessing.managers.BaseListProxy.__len__
multiprocessing.managers.BaseListProxy.__reversed__
multiprocessing.managers.BaseListProxy.reverse
Expand Down Expand Up @@ -431,6 +423,7 @@ multiprocessing.synchronize.Condition.release
multiprocessing.synchronize.SemLock.acquire
multiprocessing.synchronize.SemLock.release

numbers.Number.__hash__ # typeshed marks this as abstract but code just sets this as None
optparse.Values.__getattr__ # Some attributes are set in __init__ using setattr
os._wrap_close.read # Methods that come from __getattr__() at runtime
os._wrap_close.readable # Methods that come from __getattr__() at runtime
Expand All @@ -446,6 +439,7 @@ shutil.rmtree # function with attributes, which we approximate with a callable
ssl.PROTOCOL_SSLv2 # Depends on the existence and flags of SSL
ssl.PROTOCOL_SSLv3 # Depends on the existence and flags of SSL
sys.implementation # Actually SimpleNamespace but then you wouldn't have convenient attributes
tarfile.TarFile.errors # errors is initialized for some reason as None even though it really only accepts str
tempfile._TemporaryFileWrapper.[\w_]+ # Dynamically specified by __getattr__, and thus don't exist on the class
threading.Condition.acquire # Condition functions are exported in __init__
threading.Condition.release # Condition functions are exported in __init__
Expand Down
7 changes: 4 additions & 3 deletions stdlib/@tests/stubtest_allowlists/py38.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ _dummy_threading.Lock
_dummy_threading.RLock
_dummy_threading.Thread.native_id
asyncio.WriteTransport.get_write_buffer_limits # Documented. Exists in subclasses, but not in WriteTransport itself
asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omitted from the stub
asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub
asyncio.transports.WriteTransport.get_write_buffer_limits # Documented. Exists in subclasses, but not in WriteTransport itself
builtins.float.__set_format__ # Internal method for CPython test suite
dummy_threading.Condition.acquire
Expand Down Expand Up @@ -77,7 +75,6 @@ collections.Generator.gi_code
collections.Generator.gi_frame
collections.Generator.gi_running
collections.Generator.gi_yieldfrom
collections.Mapping.__reversed__ # Set to None at runtime for a better error message
collections.Mapping.get # Adding None to the Union messed up mypy
collections.Sequence.index # Supporting None in end is not mandatory
xxsubtype # module missing from the stubs
Expand Down Expand Up @@ -158,6 +155,9 @@ tkinter.tix.TkVersion
# Allowlist entries that cannot or should not be fixed; <= 3.8
# ============================================================

asyncio.locks._ContextManagerMixin.__enter__ # Always raises; deliberately omitted from the stub
asyncio.locks._ContextManagerMixin.__exit__ # Always raises; deliberately omitted from the stub

# Incompatible changes introduced in Python 3.8.20
# (Remove once 3.8.20 becomes available for GitHub Actions)
email._header_value_parser.NLSET
Expand All @@ -183,6 +183,7 @@ builtins.property.__get__ # Runtime signature is incorrect (https://github.com/
builtins.staticmethod.__get__ # Runtime signature is incorrect (https://github.com/python/cpython/issues/93021)
builtins.memoryview.__iter__ # C type that implements __getitem__
builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only
collections.Mapping.__reversed__ # Set to None at runtime for a better error message, omitted from typeshed

# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414.
collections.Set.__rand__
Expand Down
2 changes: 1 addition & 1 deletion stdlib/@tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ collections.Generator.gi_code
collections.Generator.gi_frame
collections.Generator.gi_running
collections.Generator.gi_yieldfrom
collections.Mapping.__reversed__ # Set to None at runtime for a better error message
collections.Mapping.get # Adding None to the Union messed up mypy
collections.Sequence.index # Supporting None in end is not mandatory
xxsubtype # module missing from the stubs
Expand Down Expand Up @@ -193,6 +192,7 @@ builtins.property.__get__ # Runtime signature is incorrect (https://github.com/
builtins.staticmethod.__get__ # Runtime signature is incorrect (https://github.com/python/cpython/issues/93021)
builtins.memoryview.__iter__ # C type that implements __getitem__
builtins.memoryview.cast # inspect.signature is incorrect about shape being kw-only
collections.Mapping.__reversed__ # Set to None at runtime for a better error message, omitted from typeshed

# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414.
collections.Set.__rand__
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_asyncio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
self,
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
loop: AbstractEventLoop | None = None,
name: str | None = ...,
context: Context | None = None,
eager_start: bool = False,
Expand All @@ -75,13 +75,13 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
self,
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
loop: AbstractEventLoop | None = None,
name: str | None = ...,
context: Context | None = None,
) -> None: ...
else:
def __init__(
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop = ..., name: str | None = ...
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, name: str | None = ...
) -> None: ...

if sys.version_info >= (3, 12):
Expand Down
24 changes: 12 additions & 12 deletions stdlib/_blake2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class blake2b:
digest_size: int
name: str
if sys.version_info >= (3, 9):
def __init__(
self,
def __new__(
cls,
data: ReadableBuffer = b"",
/,
*,
Expand All @@ -39,10 +39,10 @@ class blake2b:
inner_size: int = 0,
last_node: bool = False,
usedforsecurity: bool = True,
) -> None: ...
) -> Self: ...
else:
def __init__(
self,
def __new__(
cls,
data: ReadableBuffer = b"",
/,
*,
Expand All @@ -57,7 +57,7 @@ class blake2b:
node_depth: int = 0,
inner_size: int = 0,
last_node: bool = False,
) -> None: ...
) -> Self: ...

def copy(self) -> Self: ...
def digest(self) -> bytes: ...
Expand All @@ -74,8 +74,8 @@ class blake2s:
digest_size: int
name: str
if sys.version_info >= (3, 9):
def __init__(
self,
def __new__(
cls,
data: ReadableBuffer = b"",
/,
*,
Expand All @@ -91,10 +91,10 @@ class blake2s:
inner_size: int = 0,
last_node: bool = False,
usedforsecurity: bool = True,
) -> None: ...
) -> Self: ...
else:
def __init__(
self,
def __new__(
cls,
data: ReadableBuffer = b"",
/,
*,
Expand All @@ -109,7 +109,7 @@ class blake2s:
node_depth: int = 0,
inner_size: int = 0,
last_node: bool = False,
) -> None: ...
) -> Self: ...

def copy(self) -> Self: ...
def digest(self) -> bytes: ...
Expand Down
8 changes: 7 additions & 1 deletion stdlib/_bz2.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import sys
from _typeshed import ReadableBuffer
from typing import final
from typing_extensions import Self

@final
class BZ2Compressor:
def __init__(self, compresslevel: int = 9) -> None: ...
if sys.version_info >= (3, 12):
def __new__(cls, compresslevel: int = 9, /) -> Self: ...
else:
def __init__(self, compresslevel: int = 9, /) -> None: ...

def compress(self, data: ReadableBuffer, /) -> bytes: ...
def flush(self) -> bytes: ...

Expand Down
6 changes: 3 additions & 3 deletions stdlib/_contextvars.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from collections.abc import Callable, Iterator, Mapping
from typing import Any, ClassVar, Generic, TypeVar, final, overload
from typing_extensions import ParamSpec
from typing_extensions import ParamSpec, Self

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand All @@ -13,9 +13,9 @@ _P = ParamSpec("_P")
@final
class ContextVar(Generic[_T]):
@overload
def __init__(self, name: str) -> None: ...
def __new__(cls, name: str) -> Self: ...
@overload
def __init__(self, name: str, *, default: _T) -> None: ...
def __new__(cls, name: str, *, default: _T) -> Self: ...
def __hash__(self) -> int: ...
@property
def name(self) -> str: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Dialect:
lineterminator: str
quoting: _QuotingType
strict: bool
def __init__(
self,
def __new__(
cls,
dialect: _DialectLike | None = ...,
delimiter: str = ",",
doublequote: bool = True,
Expand All @@ -43,7 +43,7 @@ class Dialect:
quoting: _QuotingType = 0,
skipinitialspace: bool = False,
strict: bool = False,
) -> None: ...
) -> Self: ...

if sys.version_info >= (3, 10):
# This class calls itself _csv.reader.
Expand Down
14 changes: 7 additions & 7 deletions stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,18 @@ class CFuncPtr(_PointerLike, _CData, metaclass=_PyCFuncPtrType):
# Abstract attribute that must be defined on subclasses
_flags_: ClassVar[int]
@overload
def __init__(self) -> None: ...
def __new__(cls) -> Self: ...
@overload
def __init__(self, address: int, /) -> None: ...
def __new__(cls, address: int, /) -> Self: ...
@overload
def __init__(self, callable: Callable[..., Any], /) -> None: ...
def __new__(cls, callable: Callable[..., Any], /) -> Self: ...
@overload
def __init__(self, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> None: ...
def __new__(cls, func_spec: tuple[str | int, CDLL], paramflags: tuple[_PF, ...] | None = ..., /) -> Self: ...
if sys.platform == "win32":
@overload
def __init__(
self, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
) -> None: ...
def __new__(
cls, vtbl_index: int, name: str, paramflags: tuple[_PF, ...] | None = ..., iid: _CData | _CDataType | None = ..., /
) -> Self: ...

def __call__(self, *args: Any, **kwargs: Any) -> Any: ...

Expand Down
2 changes: 1 addition & 1 deletion stdlib/_io.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore
def truncate(self, pos: int | None = None, /) -> int: ...

class BufferedRWPair(BufferedIOBase, _BufferedIOBase):
def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = 8192) -> None: ...
def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = 8192, /) -> None: ...
def peek(self, size: int = 0, /) -> bytes: ...

class _TextIOBase(_IOBase):
Expand Down
9 changes: 5 additions & 4 deletions stdlib/_json.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Callable
from typing import Any, final
from typing_extensions import Self

@final
class make_encoder:
Expand All @@ -19,8 +20,8 @@ class make_encoder:
def encoder(self) -> Callable[[str], str]: ...
@property
def item_separator(self) -> str: ...
def __init__(
self,
def __new__(
cls,
markers: dict[int, Any] | None,
default: Callable[[Any], Any],
encoder: Callable[[str], str],
Expand All @@ -30,7 +31,7 @@ class make_encoder:
sort_keys: bool,
skipkeys: bool,
allow_nan: bool,
) -> None: ...
) -> Self: ...
def __call__(self, obj: object, _current_indent_level: int) -> Any: ...

@final
Expand All @@ -42,7 +43,7 @@ class make_scanner:
parse_float: Any
strict: bool
# TODO: 'context' needs the attrs above (ducktype), but not __call__.
def __init__(self, context: make_scanner) -> None: ...
def __new__(cls, context: make_scanner) -> Self: ...
def __call__(self, string: str, index: int) -> tuple[Any, int]: ...

def encode_basestring(s: str, /) -> str: ...
Expand Down
Loading

0 comments on commit 45ffe17

Please sign in to comment.