Skip to content

chore(deps): update pytype and pyright #11595

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 9 commits into from
Mar 14, 2024
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ extra-standard-library = [
known-first-party = ["parse_metadata", "utils"]

[tool.typeshed]
pyright_version = "1.1.350"
pyright_version = "1.1.354"
oldest_supported_python = "3.8"
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ flake8-noqa==1.4.0 # must match .pre-commit-config.yaml
flake8-pyi==24.3.0 # must match .pre-commit-config.yaml
mypy==1.9.0
pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml
pytype==2024.2.27; platform_system != "Windows" and python_version < "3.12"
pytype==2024.3.11; platform_system != "Windows" and python_version < "3.12"
ruff==0.3.0 # must match .pre-commit-config.yaml

# Libraries used by our various scripts.
Expand Down
2 changes: 1 addition & 1 deletion scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U

relevant_version = obsolete_since.version if obsolete_since else latest_version

project_urls = pypi_info.info["project_urls"] or {}
project_urls: dict[str, str] = pypi_info.info["project_urls"] or {}
maybe_links: dict[str, str | None] = {
"Release": f"{pypi_info.pypi_root}/{relevant_version}",
"Homepage": project_urls.get("Homepage"),
Expand Down
12 changes: 9 additions & 3 deletions stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ class UserList(MutableSequence[_T]):
def copy(self) -> Self: ...
def __copy__(self) -> Self: ...
def count(self, item: _T) -> int: ...
# All arguments are passed to `list.index` at runtime, so the signature should be kept in line with `list.index`.
def index(self, item: _T, __start: SupportsIndex = 0, __stop: SupportsIndex = sys.maxsize) -> int: ...
# The runtime signature is "item, *args", and the arguments are then passed
# to `list.index`. In order to give more precise types, we pretend that the
# `item` argument is positional-only.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit unfortunate because it disallows a legal call lst.index(item="x"). However, it's unlikely anyone would write that, and I don't see a better alternative that preserves type safety.

def index(self, item: _T, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
# All arguments are passed to `list.sort` at runtime, so the signature should be kept in line with `list.sort`.
@overload
def sort(self: UserList[SupportsRichComparisonT], *, key: None = None, reverse: bool = False) -> None: ...
Expand Down Expand Up @@ -459,7 +461,11 @@ class ChainMap(MutableMapping[_KT, _VT]):
# All arguments to `fromkeys` are passed to `dict.fromkeys` at runtime, so the signature should be kept in line with `dict.fromkeys`.
@classmethod
@overload
def fromkeys(cls, iterable: Iterable[_T], __value: None = None) -> ChainMap[_T, Any | None]: ...
def fromkeys(cls, iterable: Iterable[_T]) -> ChainMap[_T, Any | None]: ...
@classmethod
@overload
# Special-case None: the user probably wants to add non-None values later.
def fromkeys(cls, iterable: Iterable[_T], value: None, /) -> ChainMap[_T, Any | None]: ...
@classmethod
@overload
def fromkeys(cls, iterable: Iterable[_T], value: _S, /) -> ChainMap[_T, _S]: ...
Expand Down
8 changes: 5 additions & 3 deletions stdlib/dataclasses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,18 @@ if sys.version_info >= (3, 9):
else:
class _InitVarMeta(type):
# Not used, instead `InitVar.__class_getitem__` is called.
def __getitem__(self, params: Any) -> InitVar[Any]: ...
# pyright ignore is needed because pyright (not unreasonably) thinks this
# is an invalid use of InitVar.
def __getitem__(self, params: Any) -> InitVar[Any]: ... # pyright: ignore

class InitVar(Generic[_T], metaclass=_InitVarMeta):
type: Type[_T]
def __init__(self, type: Type[_T]) -> None: ...
if sys.version_info >= (3, 9):
@overload
def __class_getitem__(cls, type: Type[_T]) -> InitVar[_T]: ...
def __class_getitem__(cls, type: Type[_T]) -> InitVar[_T]: ... # pyright: ignore
@overload
def __class_getitem__(cls, type: Any) -> InitVar[Any]: ...
def __class_getitem__(cls, type: Any) -> InitVar[Any]: ... # pyright: ignore

if sys.version_info >= (3, 12):
def make_dataclass(
Expand Down
5 changes: 5 additions & 0 deletions stubs/gevent/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,8 @@ gevent.events.IPeriodicMonitorThreadStartedEvent
# internal use module for some complex protocols used across different modules
# so there wasn't really a great place for them
gevent._types

# The first parameter is technically positional-or-keyword but there's no
# useful way to use it as a keyword argument; we mark it positional-only.
gevent.pool.GroupMappingMixin.imap
gevent.pool.GroupMappingMixin.imap_unordered
88 changes: 48 additions & 40 deletions stubs/gevent/gevent/pool.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,108 +47,116 @@ class GroupMappingMixin:
self, func: Callable[[_T], _S], iterable: Iterable[_T], callback: Callable[[list[_S]], object] | None = None
) -> Greenlet[..., list[_S]]: ...
@overload
def imap(self, func: Callable[[_T1], _S], __iter1: Iterable[_T1], *, maxsize: int | None = None) -> IMap[[_T1], _S]: ...
def imap(self, func: Callable[[_T1], _S], iter1: Iterable[_T1], /, *, maxsize: int | None = None) -> IMap[[_T1], _S]: ...
@overload
def imap(
self, func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], *, maxsize: int | None = None
self, func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], iter2: Iterable[_T2], /, *, maxsize: int | None = None
) -> IMap[[_T1, _T2], _S]: ...
@overload
def imap(
self,
func: Callable[[_T1, _T2, _T3], _S],
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
iter1: Iterable[_T1],
iter2: Iterable[_T2],
iter3: Iterable[_T3],
/,
*,
maxsize: int | None = None,
) -> IMap[[_T1, _T2, _T3], _S]: ...
@overload
def imap(
self,
func: Callable[[_T1, _T2, _T3, _T4], _S],
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
iter1: Iterable[_T1],
iter2: Iterable[_T2],
iter3: Iterable[_T3],
iter4: Iterable[_T4],
/,
*,
maxsize: int | None = None,
) -> IMap[[_T1, _T2, _T3, _T4], _S]: ...
@overload
def imap(
self,
func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
__iter5: Iterable[_T5],
iter1: Iterable[_T1],
iter2: Iterable[_T2],
iter3: Iterable[_T3],
iter4: Iterable[_T4],
iter5: Iterable[_T5],
/,
*,
maxsize: int | None = None,
) -> IMap[[_T1, _T2, _T3, _T4, _T5], _S]: ...
@overload
def imap(
self,
func: Callable[_P, _S],
__iter1: Iterable[Any],
__iter2: Iterable[Any],
__iter3: Iterable[Any],
__iter4: Iterable[Any],
__iter5: Iterable[Any],
__iter6: Iterable[Any],
iter1: Iterable[Any],
iter2: Iterable[Any],
iter3: Iterable[Any],
iter4: Iterable[Any],
iter5: Iterable[Any],
iter6: Iterable[Any],
/,
*iterables: Iterable[Any],
maxsize: int | None = None,
) -> IMap[_P, _S]: ...
@overload
def imap_unordered(
self, func: Callable[[_T1], _S], __iter1: Iterable[_T1], *, maxsize: int | None = None
self, func: Callable[[_T1], _S], iter1: Iterable[_T1], /, *, maxsize: int | None = None
) -> IMapUnordered[[_T1], _S]: ...
@overload
def imap_unordered(
self, func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], *, maxsize: int | None = None
self, func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], iter2: Iterable[_T2], /, *, maxsize: int | None = None
) -> IMapUnordered[[_T1, _T2], _S]: ...
@overload
def imap_unordered(
self,
func: Callable[[_T1, _T2, _T3], _S],
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
iter1: Iterable[_T1],
iter2: Iterable[_T2],
iter3: Iterable[_T3],
/,
*,
maxsize: int | None = None,
) -> IMapUnordered[[_T1, _T2, _T3], _S]: ...
@overload
def imap_unordered(
self,
func: Callable[[_T1, _T2, _T3, _T4], _S],
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
iter1: Iterable[_T1],
iter2: Iterable[_T2],
iter3: Iterable[_T3],
iter4: Iterable[_T4],
/,
*,
maxsize: int | None = None,
) -> IMapUnordered[[_T1, _T2, _T3, _T4], _S]: ...
@overload
def imap_unordered(
self,
func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
__iter5: Iterable[_T5],
iter1: Iterable[_T1],
iter2: Iterable[_T2],
iter3: Iterable[_T3],
iter4: Iterable[_T4],
iter5: Iterable[_T5],
/,
*,
maxsize: int | None = None,
) -> IMapUnordered[[_T1, _T2, _T3, _T4, _T5], _S]: ...
@overload
def imap_unordered(
self,
func: Callable[_P, _S],
__iter1: Iterable[Any],
__iter2: Iterable[Any],
__iter3: Iterable[Any],
__iter4: Iterable[Any],
__iter5: Iterable[Any],
__iter6: Iterable[Any],
iter1: Iterable[Any],
iter2: Iterable[Any],
iter3: Iterable[Any],
iter4: Iterable[Any],
iter5: Iterable[Any],
iter6: Iterable[Any],
/,
*iterables: Iterable[Any],
maxsize: int | None = None,
) -> IMapUnordered[_P, _S]: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/gevent/gevent/resolver/cares.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if sys.platform != "win32":

class ares_host_result(tuple[str, list[str], list[str]]):
family: int
def __new__(cls, family: int, __hostname: str, __aliases: list[str], __addr_list: list[str]) -> Self: ...
def __new__(cls, family: int, hostname: str, aliases: list[str], addr_list: list[str], /) -> Self: ...

class channel:
@property
Expand Down
1 change: 1 addition & 0 deletions tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several p
builtins.float.__setformat__ # Internal method for CPython test suite
builtins.property.__set_name__ # Doesn't actually exist
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
collections\.UserList\.index # ignoring pos-or-keyword parameter
configparser.ParsingError.filename
contextlib.AbstractAsyncContextManager.__class_getitem__
contextlib.AbstractContextManager.__class_getitem__
Expand Down
1 change: 1 addition & 0 deletions tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _csv.Writer
bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
configparser.LegacyInterpolation.__init__
configparser.ParsingError.filename
collections\.UserList\.index # ignoring pos-or-keyword parameter
enum.Enum.__init__
enum.Enum._generate_next_value_
# Not strictly speaking a staticmethod on 3.11, but it acts like one:
Expand Down
1 change: 1 addition & 0 deletions tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ _weakref.ProxyType.__reversed__ # Doesn't really exist
argparse._MutuallyExclusiveGroup.add_mutually_exclusive_group # deprecated, forwards arguments to super
ast.ImportFrom.level # None on the class, but never None on instances
builtins.property.__set_name__ # Doesn't actually exist
collections\.UserList\.index # ignoring pos-or-keyword parameter
dataclasses.KW_ONLY # white lies around defaults
enum.auto.__init__ # The stub for enum.auto is nothing like the implementation
enum.auto.value # The stub for enum.auto is nothing like the implementation
Expand Down
4 changes: 2 additions & 2 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several p
asyncio.Future.__init__ # Usually initialized from c object
asyncio.futures.Future.__init__ # Usually initialized from c object
builtins.dict.get
collections.ChainMap.fromkeys # Runtime has *args which can really only be one argument
collections.UserList.sort # Runtime has *args but will error if any are supplied
collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023
collections\.UserList\.sort # Runtime has *args but will error if any are supplied
configparser.SectionProxy.__getattr__ # SectionProxy can have arbitrary attributes when custom converters are used
# SectionProxy get functions are set in __init__
configparser.SectionProxy.getboolean
Expand Down