8000 Update `Unused` parameters in `stubs/` by Avasam · Pull Request #9704 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Update Unused parameters in stubs/ #9704

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 4 commits into from
Feb 22, 2023
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
Prev Previous commit
Next Next commit
Replace unused object parameters with Unused alias
  • Loading branch information
Avasam committed Feb 10, 2023
commit daf475c831e02863c45001c4d35bcc472f74a4f4
4 changes: 2 additions & 2 deletions stubs/Pillow/PIL/PSDraw.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from _typeshed import SupportsWrite
from _typeshed import SupportsWrite, Unused

from .Image import Image

class PSDraw:
fp: SupportsWrite[bytes]
def __init__(self, fp: SupportsWrite[bytes] | None = ...) -> None: ...
isofont: dict[bytes, int]
def begin_document(self, id: object = None) -> None: ...
def begin_document(self, id: Unused = None) -> None: ...
def end_document(self) -> None: ...
def setfont(self, font: str, size: int) -> None: ...
def line(self, xy0: tuple[int, int], xy1: tuple[int, int]) -> None: ...
Expand Down
3 changes: 2 additions & 1 deletion stubs/PyMySQL/pymysql/converters.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import time
from _typeshed import Unused
from collections.abc import Callable, Mapping, Sequence
from decimal import Decimal
from typing import Any, TypeVar
Expand All @@ -25,7 +26,7 @@ def escape_time(obj: datetime.time, mapping: _EscaperMapping = ...) -> str: ...
def escape_datetime(obj: datetime.datetime, mapping: _EscaperMapping = ...) -> str: ...
def escape_date(obj: datetime.date, mapping: _EscaperMapping = ...) -> str: ...
def escape_struct_time(obj: time.struct_time, mapping: _EscaperMapping = ...) -> str: ...
def Decimal2Literal(o: Decimal, d: object) -> str: ...
def Decimal2Literal(o: Decimal, d: Unused) -> str: ...
def convert_datetime(obj: str | bytes) -> datetime.datetime | str: ...
def convert_timedelta(obj: str | bytes) -> datetime.timedelta | str: ...
def convert_time(obj: str | bytes) -> datetime.time | str: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/SQLAlchemy/sqlalchemy/engine/url.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Self, SupportsItems
from _typeshed import Self, SupportsItems, Unused
from collections.abc import Iterable, Mapping, Sequence
from typing import Any, NamedTuple
from typing_extensions import TypeAlias
Expand Down Expand Up @@ -52,7 +52,7 @@ class URL(_URLTuple):
def __to_string__(self, hide_password: bool = ...) -> str: ...
def render_as_string(self, hide_password: bool = ...) -> str: ...
def __copy__(self: Self) -> Self: ...
def __deepcopy__(self: Self, memo: object) -> Self: ...
def __deepcopy__(self: Self, memo: Unused) -> Self: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
Expand Down
6 changes: 3 additions & 3 deletions stubs/SQLAlchemy/sqlalchemy/log.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Self
from _typeshed import Self, Unused
from logging import Logger
from typing import Any, TypeVar, overload
from typing_extensions import Literal, TypeAlias
Expand Down Expand Up @@ -33,7 +33,7 @@ def instance_logger(instance: Identified, echoflag: _EchoFlag = ...) -> None: ..
class echo_property:
__doc__: str
@overload
def __get__(self: Self, instance: None, owner: object) -> Self: ...
def __get__(self: Self, instance: None, owner: Unused) -> Self: ...
@overload
def __get__(self, instance: Identified, owner: object) -> _EchoFlag: ...
def __get__(self, instance: Identified, owner: Unused) -> _EchoFlag: ...
def __set__(self, instance: Identified, value: _EchoFlag) -> None: ...
4 changes: 2 additions & 2 deletions stubs/SQLAlchemy/sqlalchemy/orm/decl_api.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete
from _typeshed import Incomplete, Unused
from collections.abc import Callable
from typing import Any, ClassVar, TypeVar, overload
from typing_extensions import TypeAlias
Expand Down Expand Up @@ -28,7 +28,7 @@ _DeclarativeBaseMeta: TypeAlias = Callable[[str, tuple[type[Any], ...], dict[str
def has_inherited_table(cls: type[Any]) -> bool: ...

class DeclarativeMeta(type):
def __init__(cls, classname: str, bases: tuple[type[Any], ...], dict_: dict[str, Any], **kw: object) -> None: ...
def __init__(cls, classname: str, bases: tuple[type[Any], ...], dict_: dict[str, Any], **kw: Unused) -> None: ...
def __setattr__(cls, key: str, value: Any) -> None: ...
def __delattr__(cls, key: str) -> None: ...

Expand Down
8 changes: 4 additions & 4 deletions stubs/SQLAlchemy/sqlalchemy/util/_collections.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import collections.abc
from _typeshed import Incomplete, Self, SupportsKeysAndGetItem
from _typeshed import Incomplete, Self, SupportsKeysAndGetItem, Unused
from collections.abc import Callable, Iterable, Iterator, Mapping
from typing import Any, Generic, NoReturn, TypeVar, overload

Expand All @@ -15,9 +15,9 @@ collections_abc = collections.abc
EMPTY_SET: frozenset[Any]

class ImmutableContainer:
def __delitem__(self, *arg: object, **kw: object) -> NoReturn: ...
def __setitem__(self, *arg: object, **kw: object) -> NoReturn: ...
def __setattr__(self, *arg: object, **kw: object) -> NoReturn: ...
def __delitem__(self, *arg: Unused, **kw: Unused) -> NoReturn: ...
def __setitem__(self, *arg: Unused, **kw: Unused) -> NoReturn: ...
def __setattr__(self, *arg: Unused, **kw: Unused) -> NoReturn: ...
Comment on lines +19 to +21
Copy link
Member

Choose a reason for hiding this comment

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

(I haven't looked at the source code here, just speculating.)

If instances of ImmutableContainer are meant to be, well, immutable, it might produce better type checking if we just omitted these methods from the stub altogether.

Copy link
Collaborator Author
@Avasam Avasam Feb 22, 2023

Choose a reason for hiding this comment

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

Maybe relevant to your question:
microsoft/pyright#4653 (comment)
python/mypy#14726


@overload
def coerce_to_immutabledict(d: None) -> immutabledict[Any, Any]: ...
Expand Down
10 changes: 5 additions & 5 deletions stubs/SQLAlchemy/sqlalchemy/util/langhelpers.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, Self
from _typeshed import Incomplete, Self, Unused
from collections.abc import Callable
from typing import Any, Generic, TypeVar, overload

Expand Down Expand Up @@ -70,9 +70,9 @@ class memoized_property(Generic[_R]):
__name__: str
def __init__(self, fget: Callable[..., _R], doc: str | None = ...) -> None: ...
@overload
def __get__(self: Self, obj: None, cls: object) -> Self: ...
def __get__(self: Self, obj: None, cls: Unused) -> Self: ...
@overload
def __get__(self, obj: object, cls: object) -> _R: ...
def __get__(self, obj: object, cls: Unused) -> _R: ...
@classmethod
def reset(cls, obj: object, name: str) -> None: ...

Expand All @@ -85,9 +85,9 @@ class HasMemoized:
__name__: str
def __init__(self, fget: Callable[..., _R], doc: str | None = ...) -> None: ...
@overload
def __get__(self: Self, obj: None, cls: object) -> Self: ...
def __get__(self: Self, obj: None, cls: Unused) -> Self: ...
@overload
def __get__(self, obj: object, cls: object) -> _R: ...
def __get__(self, obj: object, cls: Unused) -> _R: ...

@classmethod
def memoized_instancemethod(cls, fn): ...
Expand Down
3 changes: 2 additions & 1 deletion stubs/cachetools/cachetools/keys.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from _typeshed import Unused
from collections.abc import Hashable

__all__ = ("hashkey", "methodkey", "typedkey")

def hashkey(*args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ...
def methodkey(self: object, *args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ...
def methodkey(self: Unused, *args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ...
def typedkey(*args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ...
4 changes: 2 additions & 2 deletions stubs/croniter/croniter/croniter.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from _typeshed import ReadableBuffer, Self
from _typeshed import ReadableBuffer, Self, Unused
from collections import OrderedDict
from collections.abc import Iterator
from re import Match, Pattern
Expand Down Expand Up @@ -121,7 +121,7 @@ class HashExpander:
range_end: int | None = None,
range_begin: int | None = None,
) -> int: ...
def match(self, efl: object, idx: object, expr: str, hash_id: object = None, **kw: object) -> Match[str] | None: ...
def match(self, efl: Unused, idx: Unused, expr: str, hash_id: Unused = None, **kw: Unused) -> Match[str] | None: ...
def expand(
self,
efl: object,
Expand Down
3 changes: 2 additions & 1 deletion stubs/docutils/docutils/io.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from _typeshed import (
OpenTextModeReading,
OpenTextModeWriting,
SupportsWrite,
Unused,
)
from re import Pattern
from typing import Any, ClassVar
Expand Down Expand Up @@ -88,7 +89,7 @@ class NullInput(Input):

class NullOutput(Output):
default_destination_path: ClassVar[str]
def write(self, data: object) -> None: ...
def write(self, data: Unused) -> None: ...

class DocTreeInput(Input):
default_source_path: ClassVar[str]
4 changes: 2 additions & 2 deletions stubs/fpdf2/fpdf/html.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete
from _typeshed import Incomplete, Unused
from collections.abc import Callable
from html.parser import HTMLParser
from logging import Logger
Expand Down Expand Up @@ -68,7 +68,7 @@ class HTML2FPDF(HTMLParser):
ul_bullet_char: str = ...,
heading_sizes: Incomplete | None = None,
warn_on_tags_not_matching: bool = True,
**_: object,
**_: Unused,
): ...
def width2unit(self, length): ...
def handle_data(self, data) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/fpdf2/fpdf/output.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete
from _typeshed import Incomplete, Unused
from collections import defaultdict
from logging import Logger
from typing_extensions import Final
Expand Down Expand Up @@ -165,7 +165,7 @@ class PDFPagesRoot(PDFObject):

class PDFExtGState(PDFObject):
def __init__(self, dict_as_str) -> None: ...
def serialize(self, obj_dict: object = None, _security_handler: StandardSecurityHandler | None = None) -> str: ...
def serialize(self, obj_dict: Unused = None, _security_handler: StandardSecurityHandler | None = None) -> str: ...

class PDFXrefAndTrailer(ContentWithoutID):
output_builder: Incomplete
Expand Down
4 changes: 2 additions & 2 deletions stubs/fpdf2/fpdf/structure_tree.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete
from _typeshed import Incomplete, Unused
from collections import defaultdict
from collections.abc import Generator, Iterable

Expand All @@ -8,7 +8,7 @@ from .syntax import PDFArray, PDFObject, PDFString
class NumberTree(PDFObject):
nums: defaultdict[Incomplete, list[Incomplete]]
def __init__(self) -> None: ...
def serialize(self, obj_dict: object = ..., _security_handler: StandardSecurityHandler | None = None) -> str: ...
def serialize(self, obj_dict: Unused = None, _security_handler: StandardSecurityHandler | None = None) -> str: ...

class StructTreeRoot(PDFObject):
type: str
Expand Down
6 changes: 3 additions & 3 deletions stubs/google-cloud-ndb/google/cloud/ndb/model.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from _typeshed import Self
from _typeshed import Self, Unused
from collections.abc import Callable, Iterable, Sequence
from typing import Any, NoReturn
from typing_extensions import Literal, TypeAlias
Expand Down Expand Up @@ -504,5 +504,5 @@ def delete_multi(
force_writes: bool | None = ...,
_options: object = None,
) -> list[None]: ...
def get_indexes_async(**options: object) -> NoReturn: ...
def get_indexes(**options: object) -> NoReturn: ...
def get_indexes_async(**options: Unused) -> NoReturn: ...
def get_indexes(**options: Unused) -> NoReturn: ...
4 changes: 2 additions & 2 deletions stubs/mypy-extensions/mypy_extensions.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abc
import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import IdentityFunction, Self
from _typeshed import IdentityFunction, Self, Unused
from collections.abc import Mapping
from typing import Any, ClassVar, Generic, TypeVar, overload, type_check_only
from typing_extensions import Never
Expand Down Expand Up @@ -65,7 +65,7 @@ class NoReturn: ...
# a class decorator, but mypy does not support type[_T] for abstract
# classes until this issue is resolved, https://github.com/python/mypy/issues/4717.
def trait(cls: _T) -> _T: ...
def mypyc_attr(*attrs: str, **kwattrs: object) -> IdentityFunction: ...
def mypyc_attr(*attrs: str, **kwattrs: Unused) -> IdentityFunction: ...

class FlexibleAlias(Generic[_T, _U]): ...

Expand Down
5 changes: 3 additions & 2 deletions stubs/mysqlclient/MySQLdb/times.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Unused
from datetime import date, datetime, time, timedelta

from MySQLdb._mysql import string_literal as string_literal
Expand All @@ -22,5 +23,5 @@ def DateTime_or_None(s: str) -> datetime | None: ...
def TimeDelta_or_None(s: str) -> timedelta | None: ...
def Time_or_None(s: str) -> time | None: ...
def Date_or_None(s: str) -> date | None: ...
def DateTime2literal(d: datetime, c: object) -> str: ...
def DateTimeDelta2literal(d: datetime, c: object) -> str: ...
def DateTime2literal(d: datetime, c: Unused) -> str: ...
def DateTimeDelta2literal(d: datetime, c: Unused) -> str: ...
4 changes: 2 additions & 2 deletions stubs/netaddr/netaddr/ip/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, Self
from _typeshed import Incomplete, Self, Unused
from abc import abstractmethod
from collections.abc import Iterable, Iterator
from typing import SupportsInt, overload
Expand Down Expand Up @@ -133,7 +133,7 @@ class IPNetwork(BaseIP, IPListMixin):
def previous(self: Self, step: int = ...) -> Self: ...
def next(self: Self, step: int = ...) -> Self: ...
def supernet(self, prefixlen: int = ...) -> list[IPNetwork]: ...
def subnet(self: Self, prefixlen: int, count: int | None = ..., fmt: object = None) -> Iterator[Self]: ...
def subnet(self: Self, prefixlen: int, count: int | None = ..., fmt: Unused = None) -> Iterator[Self]: ...
def iter_hosts(self) -> Iterator[IPAddress]: ...

class IPRange(BaseIP, IPListMixin):
Expand Down
3 changes: 2 additions & 1 deletion stubs/netaddr/netaddr/strategy/ipv4.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Unused
from collections.abc import Iterable, Sequence
from socket import AddressFamily
from typing_extensions import Literal
Expand All @@ -22,7 +23,7 @@ hostmask_to_prefix: dict[int, int]

def valid_str(addr: str, flags: int = ...) -> bool: ...
def str_to_int(addr: str, flags: int = ...) -> int: ...
def int_to_str(int_val: int, dialect: object = None) -> str: ...
def int_to_str(int_val: int, dialect: Unused = None) -> str: ...
def int_to_arpa(int_val: int) -> str: ...
def int_to_packed(int_val: int) -> bytes: ...
def packed_to_int(packed_int: bytes) -> int: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/paho-mqtt/paho/mqtt/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import socket as _socket
import ssl as _ssl
import time
import types
from _typeshed import Incomplete
from _typeshed import Incomplete, Unused
from collections.abc import Callable
from typing import Any, TypeVar
from typing_extensions import TypeAlias
Expand Down Expand Up @@ -225,7 +225,7 @@ class Client:
def loop_misc(self) -> int: ...
def max_inflight_messages_set(self, inflight: int) -> None: ...
def max_queued_messages_set(self, queue_size: int) -> Client: ...
def message_retry_set(self, retry: object) -> None: ...
def message_retry_set(self, retry: Unused) -> None: ...
def user_data_set(self, userdata: _UserData) -> None: ...
def will_set(
self, topic: str, payload: _Payload | None = ..., qos: int = ..., retain: bool = ..., properties: Properties | None = ...
Expand Down
6 changes: 3 additions & 3 deletions stubs/pyasn1/pyasn1/type/base.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from _typeshed import Incomplete
from typing import type_check_only
from _typeshed import Incomplete, Unused
from typing import NoReturn, type_check_only
from typing_extensions import final

from pyasn1.type import constraint, namedtype
Expand Down Expand Up @@ -41,7 +41,7 @@ class NoValue:
def __getattr__(self, attr) -> None: ...
# def __new__.<locals>.getPlug.<locals>.plug
@type_check_only
def plug(self, *args: object, **kw: object): ...
def plug(self, *args: Unused, **kw: Unused) -> NoReturn: ...
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand why this method is in the stub at all.

Copy link
Collaborator Author
@Avasam Avasam Feb 22, 2023

Choose a reason for hiding this comment

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

Pretty sure it's just to use as an alias below. Source: https://github.com/pyasn1/pyasn1/blob/main/pyasn1/type/base.py#L212 (which the comment also point to being defined in the function getPlug in the function __new__)

# Magic methods assigned dynamically, priority from right to left: plug < str < int < list < dict
__abs__ = int.__abs__
__add__ = list.__add__
Expand Down
4 changes: 2 additions & 2 deletions stubs/python-crontab/crontab.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import subprocess
from _typeshed import Incomplete, Self
from _typeshed import Incomplete, Self, Unused
from builtins import range as _range
from collections import OrderedDict
from collections.abc import Callable, Generator, Iterable, Iterator
Expand Down Expand Up @@ -70,7 +70,7 @@ class CronTab:
# work for `CronItem` subclasses, which might define other kwargs.
def run_pending(self, **kwargs: Any) -> Iterator[str]: ...
# There are two known kwargs and others are unused:
def run_scheduler(self, timeout: int = ..., *, warp: object = ..., cadence: int = ..., **kwargs: object) -> Iterator[str]: ...
def run_scheduler(self, timeout: int = ..., *, warp: object = ..., cadence: int = ..., **kwargs: Unused) -> Iterator[str]: ...
def render(self, errors: bool = ..., specials: bool | None = ...) -> str: ...
def new(
self,
Expand Down
7 changes: 4 additions & 3 deletions stubs/pytz/pytz/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from _typeshed import Unused
from collections.abc import Mapping
from typing import ClassVar

Expand Down Expand Up @@ -26,9 +27,9 @@ def timezone(zone: str) -> _UTCclass | StaticTzInfo | DstTzInfo: ...
class _FixedOffset(datetime.tzinfo):
zone: ClassVar[None]
def __init__(self, minutes: int) -> None: ...
def utcoffset(self, dt: object) -> datetime.timedelta | None: ...
def dst(self, dt: object) -> datetime.timedelta: ...
def tzname(self, dt: object) -> None: ...
def utcoffset(self, dt: Unused) -> datetime.timedelta | None: ...
def dst(self, dt: Unused) -> datetime.timedelta: ...
def tzname(self, dt: Unused) -> None: ...
def localize(self, dt: datetime.datetime, is_dst: bool = ...) -> datetime.datetime: ...
def normalize(self, dt: datetime.datetime, is_dst: bool = ...) -> datetime.datetime: ...

Expand Down
6 changes: 3 additions & 3 deletions stubs/redis/redis/cluster.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, Self
from _typeshed import Incomplete, Self, Unused
from collections.abc import Callable, Iterable, Sequence
from threading import Lock
from types import TracebackType
Expand All @@ -15,8 +15,8 @@ from redis.typing import EncodableT

def get_node_name(host: str, port: str | int) -> str: ...
def get_connection(redis_node: Redis[Any], *args, **options: _ConnectionPoolOptions) -> Connection: ...
def parse_scan_result(command: object, res, **options): ...
def parse_pubsub_numsub(command: object, res, **options: object): ...
def parse_scan_result(command: Unused, res, **options): ...
def parse_pubsub_numsub(command: Unused, res, **options: Unused): ...
def parse_cluster_slots(resp, **options) -> dict[tuple[int, int], dict[str, Any]]: ...

PRIMARY: str
Expand Down
Loading
0