diff --git a/stubs/boltons/boltons/cacheutils.pyi b/stubs/boltons/boltons/cacheutils.pyi index 178171647c31..fe00700c3299 100644 --- a/stubs/boltons/boltons/cacheutils.pyi +++ b/stubs/boltons/boltons/cacheutils.pyi @@ -1,7 +1,8 @@ import weakref -from _typeshed import Incomplete, Self, SupportsItems, SupportsKeysAndGetItem +from _typeshed import Incomplete, SupportsItems, SupportsKeysAndGetItem from collections.abc import Callable, Generator, Hashable, Iterable, Iterator, Mapping from typing import Any, Generic, TypeVar, overload +from typing_extensions import Self _KT = TypeVar("_KT") _VT = TypeVar("_VT") @@ -18,8 +19,10 @@ class LRI(dict[_KT, _VT]): miss_count: int soft_miss_count: int max_size: int - on_miss: Callable[[_KT], _VT] - def __init__(self, max_size: int = 128, values: Incomplete | None = None, on_miss: Incomplete | None = None) -> None: ... + on_miss: Callable[[_KT], _VT] | None + def __init__( + self, max_size: int = 128, values: Incomplete | None = None, on_miss: Callable[[_KT], _VT] | None = None + ) -> None: ... def __setitem__(self, key: _KT, value: _VT) -> None: ... def __getitem__(self, key: _KT) -> _VT: ... @overload @@ -33,9 +36,9 @@ class LRI(dict[_KT, _VT]): def pop(self, key: _KT, default: _T) -> _T | _VT: ... def popitem(self) -> tuple[_KT, _VT]: ... def clear(self) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... @overload - def setdefault(self, key: _KT, default: None = None) -> _VT: ... + def setdefault(self, key: _KT, default: None = None) -> _VT | None: ... @overload def setdefault(self, key: _KT, default: _VT) -> _VT: ... def update(self, E: SupportsKeysAndGetItem[_KT, _VT] | Iterable[tuple[_KT, _VT]], **F: _VT) -> None: ... # type: ignore[override] @@ -57,7 +60,14 @@ class CachedFunction: scoped: Incomplete typed: Incomplete key_func: Incomplete - def __init__(self, func, cache, scoped: bool = True, typed: bool = False, key: Incomplete | None = None): ... + def __init__( + self, + func, + cache: Mapping[Any, Any] | Callable[..., Incomplete], + scoped: bool = True, + typed: bool = False, + key: Callable[..., Incomplete] | None = None, + ): ... def __call__(self, *args, **kwargs): ... class CachedMethod: @@ -67,17 +77,37 @@ class CachedMethod: typed: Incomplete key_func: Incomplete bound_to: Incomplete - def __init__(self, func, cache, scoped: bool = True, typed: bool = False, key: Incomplete | None = None): ... + def __init__( + self, + func, + cache: Mapping[Any, Any] | Callable[..., Incomplete], + scoped: bool = True, + typed: bool = False, + key: Callable[..., Incomplete] | None = None, + ): ... def __get__(self, obj, objtype: Incomplete | None = None): ... def __call__(self, *args, **kwargs): ... -def cached(cache: Mapping[Any, Any], scoped: bool = True, typed: bool = False, key: Incomplete | None = None): ... -def cachedmethod(cache, scoped: bool = True, typed: bool = False, key: Incomplete | None = None): ... +def cached( + cache: Mapping[Any, Any] | Callable[..., Incomplete], + scoped: bool = True, + typed: bool = False, + key: Callable[..., Incomplete] | None = None, +): ... +def cachedmethod( + cache: Mapping[Any, Any] | Callable[..., Incomplete], + scoped: bool = True, + typed: bool = False, + key: Callable[..., Incomplete] | None = None, +): ... -class cachedproperty(Generic[_T]): - func: Callable[[Incomplete], _T] - def __init__(self, func: Callable[[Incomplete], _T]) -> None: ... - def __get__(self, obj: _T, objtype: type | None = None): ... +class cachedproperty(Generic[_KT, _VT]): + func: Callable[[_KT], _VT] + def __init__(self, func: Callable[[_KT], _VT]) -> None: ... + @overload + def __get__(self, obj: None, objtype: type | None = None) -> Self: ... + @overload + def __get__(self, obj: _KT, objtype: type | None = None) -> _VT: ... class ThresholdCounter(Generic[_T]): total: int @@ -103,8 +133,8 @@ class ThresholdCounter(Generic[_T]): def update(self, iterable: Iterable[_T] | Mapping[_T, int], **kwargs: Iterable[_T] | Mapping[_T, int]) -> None: ... class MinIDMap(Generic[_T]): - mapping: weakref.WeakKeyDictionary[_T, int] - ref_map: dict[_T, int] + mapping: weakref.WeakKeyDictionary[_T, tuple[int, weakref.ReferenceType[_T]]] + ref_map: dict[weakref.ReferenceType[_T], int] free: list[int] def __init__(self) -> None: ... def get(self, a: _T) -> int: ... diff --git a/stubs/boltons/boltons/dictutils.pyi b/stubs/boltons/boltons/dictutils.pyi index 2b74aaaf2f63..26c99bb70eb9 100644 --- a/stubs/boltons/boltons/dictutils.pyi +++ b/stubs/boltons/boltons/dictutils.pyi @@ -1,7 +1,6 @@ from _typeshed import SupportsKeysAndGetItem -from binascii import Incomplete from collections.abc import Generator, ItemsView, Iterable, KeysView, ValuesView -from typing import NoReturn, TypeVar +from typing import NoReturn, TypeVar, overload from typing_extensions import Self, TypeAlias _KT = TypeVar("_KT") @@ -13,26 +12,32 @@ class OrderedMultiDict(dict[_KT, _VT]): def addlist(self, k: _KT, v: Iterable[_VT]) -> None: ... def clear(self) -> None: ... def copy(self) -> Self: ... - def counts(self) -> OrderedMultiDict[_KT, _VT]: ... + def counts(self) -> Self: ... @classmethod - def fromkeys(cls, keys: _KT, default: _VT | None = None) -> OrderedMultiDict[_KT, _VT]: ... # type: ignore[override] - def get(self, k: _KT, default: _VT | None = None) -> OrderedMultiDict[_KT, _VT]: ... # type: ignore[override] - def getlist(self, k: _KT, default: _VT | None = ...) -> list[object]: ... - def inverted(self) -> OrderedMultiDict[_KT, _VT]: ... + def fromkeys(cls, keys: _KT, default: _VT | None = None) -> Self: ... # type: ignore[override] + @overload # type: ignore[override] + def get(self, k: _KT, default: None = None) -> _VT | None: ... + @overload + def get(self, k: _KT, default: _VT) -> _VT: ... + def getlist(self, k: _KT, default: list[_VT] = ...) -> list[_VT]: ... + def inverted(self) -> Self: ... def items(self, multi: bool = False) -> list[tuple[_KT, _VT]]: ... # type: ignore[override] def iteritems(self, multi: bool = False) -> Generator[tuple[_KT, _VT], None, None]: ... def iterkeys(self, multi: bool = False) -> Generator[_KT, None, None]: ... def itervalues(self, multi: bool = False) -> Generator[_VT, None, None]: ... def keys(self, multi: bool = False) -> list[_KT]: ... # type: ignore[override] - def pop(self, k: _KT, default: _VT | None = ...) -> _VT: ... # type: ignore[override] - def popall(self, k: _KT, default: _VT | None = ...) -> list[_VT]: ... - def poplast(self, k: _KT | None = ..., default: _VT | None = ...) -> _VT: ... - def setdefault(self, k: _KT, default: _VT | None = ...) -> _VT: ... - def sorted(self, key: _KT | None = None, reverse: bool = False) -> OrderedMultiDict[_KT, _VT]: ... - def sortedvalues(self, key: _KT | None = None, reverse: bool = False) -> OrderedMultiDict[_KT, _VT]: ... + def pop(self, k: _KT, default: _VT = ...) -> _VT: ... # type: ignore[override] + def popall(self, k: _KT, default: _VT = ...) -> list[_VT]: ... + def poplast(self, k: _KT = ..., default: _VT = ...) -> _VT: ... + @overload # type: ignore[override] + def setdefault(self, k: _KT, default: None = ...) -> _VT | None: ... + @overload + def setdefault(self, k: _KT, default: _VT) -> _VT: ... + def sorted(self, key: _KT | None = None, reverse: bool = False) -> Self: ... + def sortedvalues(self, key: _KT | None = None, reverse: bool = False) -> Self: ... def todict(self, multi: bool = False) -> dict[_KT, _VT]: ... - def update(self, E: dict[_KT, _VT] | Iterable[object], **F) -> None: ... # type: ignore[override] - def update_extend(self, E: dict[_KT, _VT] | Iterable[object], **F) -> None: ... + def update(self, E: SupportsKeysAndGetItem[_KT, _VT] | Iterable[tuple[_KT, _VT]], **F) -> None: ... # type: ignore[override] + def update_extend(self, E: SupportsKeysAndGetItem[_KT, _VT] | Iterable[tuple[_KT, _VT]], **F) -> None: ... def values(self, multi: bool = False) -> list[_VT]: ... # type: ignore[override] def viewitems(self) -> ItemsView[_KT, _VT]: ... def viewkeys(self) -> KeysView[_KT]: ... @@ -46,7 +51,7 @@ class FastIterOrderedMultiDict(OrderedMultiDict[_KT, _VT]): # undocumented def iterkeys(self, multi: bool = False) -> Generator[_KT, None, None]: ... class OneToOne(dict[_KT, _VT]): - inv: dict[_VT, _KT] + inv: OneToOne[_VT, _KT] def clear(self) -> None: ... def copy(self) -> Self: ... def pop(self, key: _KT, default: _VT | _T = ...) -> _VT | _T: ... @@ -63,7 +68,9 @@ class ManyToMany(dict[_KT, frozenset[_VT]]): def __delitem__(self, key: _KT) -> None: ... def __eq__(self, other): ... def __getitem__(self, key: _KT): ... - def __init__(self, items: Iterable[Incomplete] | None = None) -> None: ... + def __init__( + self, items: ManyToMany[_KT, _VT] | SupportsKeysAndGetItem[_KT, _VT] | tuple[_KT, _VT] | None = None + ) -> None: ... def __iter__(self): ... def __len__(self): ... def __setitem__(self, key: _KT, vals: Iterable[_VT]) -> None: ... @@ -81,10 +88,16 @@ class FrozenHashError(TypeError): ... # undocumented class FrozenDict(dict[_KT, _VT]): def __copy__(self) -> Self: ... - def clear(self, *a, **kw) -> None: ... @classmethod - def fromkeys(cls, keys: Iterable[_KT], value: _VT | None = None) -> FrozenDict[_KT, _VT]: ... # type: ignore[override] + def fromkeys(cls, keys: Iterable[_KT], value: _VT | None = None) -> Self: ... # type: ignore[override] + def updated(self, *a, **kw) -> Self: ... + # Can't noqa because of https://github.com/plinss/flake8-noqa/pull/30 + # Signature conflicts with superclass, so let's just omit it + # def __ior__(self, *a, **kw) -> NoReturn: ... + def __setitem__(self, *a, **kw) -> NoReturn: ... + def __delitem__(self, *a, **kw) -> NoReturn: ... + def update(self, *a, **kw) -> NoReturn: ... def pop(self, *a, **kw) -> NoReturn: ... def popitem(self, *a, **kw) -> NoReturn: ... def setdefault(self, *a, **kw) -> NoReturn: ... - def updated(self, *a, **kw) -> Self: ... + def clear(self, *a, **kw) -> NoReturn: ... diff --git a/stubs/boltons/boltons/fileutils.pyi b/stubs/boltons/boltons/fileutils.pyi index a371c5378a0c..df8ca79090a4 100644 --- a/stubs/boltons/boltons/fileutils.pyi +++ b/stubs/boltons/boltons/fileutils.pyi @@ -1,10 +1,13 @@ -from _typeshed import StrOrBytesPath +from _typeshed import BytesPath, StrOrBytesPath, StrPath from collections.abc import Callable, Generator, Iterable from os import PathLike from types import TracebackType -from typing import IO, Any, NoReturn +from typing import IO, Any, NoReturn, TypeVar, overload from typing_extensions import Self +_StrPathT = TypeVar("_StrPathT", bound=StrPath) +_BytesPathT = TypeVar("_BytesPathT", bound=BytesPath) + def mkdir_p(path: StrOrBytesPath) -> None: ... def rotate_file(filename: PathLike[str], *, keep: int = 5) -> None: ... @@ -24,9 +27,9 @@ def atomic_save(dest_path: str, **kwargs) -> AtomicSaver: ... class AtomicSaver: dest_path: str overwrite: bool - file_perms: int + file_perms: int | None overwrite_part: bool - part_filename: str + part_filename: str | None rm_part_on_exc: bool text_mode: bool buffering: int @@ -49,17 +52,22 @@ def iter_find_files( include_dirs: bool = False, max_depth: int | None = None, ) -> Generator[str, None, None]: ... +@overload +def copy_tree( + src: _StrPathT, dst: _StrPathT, symlinks: bool = False, ignore: Callable[[_StrPathT, list[str]], Iterable[str]] | None = None +) -> None: ... +@overload def copy_tree( - src: StrOrBytesPath, - dst: StrOrBytesPath, + src: _BytesPathT, + dst: _BytesPathT, symlinks: bool = False, - ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrOrBytesPath, list[str]], Iterable[str]] = None, + ignore: Callable[[_BytesPathT, list[bytes]], Iterable[bytes]] | None = None, ) -> None: ... copytree = copy_tree class DummyFile: - name: str + name: StrOrBytesPath mode: str closed: bool errors: None diff --git a/stubs/boltons/boltons/formatutils.pyi b/stubs/boltons/boltons/formatutils.pyi index 20ac5f0a83b0..1f0656877975 100644 --- a/stubs/boltons/boltons/formatutils.pyi +++ b/stubs/boltons/boltons/formatutils.pyi @@ -1,7 +1,9 @@ from collections.abc import Callable -from typing import Any +from typing import Generic, TypeVar -def construct_format_field_str(fname: str, fspec: str, conv: str) -> str: ... +_T = TypeVar("_T") + +def construct_format_field_str(fname: str | None, fspec: str | None, conv: str | None) -> str: ... def infer_positional_format_args(fstr: str) -> str: ... def get_format_args(fstr: str) -> tuple[list[tuple[int, type]], list[tuple[str, type]]]: ... def tokenize_format_str(fstr: str, resolve_pos: bool = True) -> list[str | BaseFormatField]: ... @@ -18,17 +20,17 @@ class BaseFormatField: type_char: str type_func: str def set_fspec(self, fspec) -> None: ... - conv: str + conv: str | None conv_func: str | None - def set_conv(self, conv: str) -> None: ... + def set_conv(self, conv: str | None) -> None: ... @property def fstr(self) -> str: ... -class DeferredValue: - func: Callable[..., Any] +class DeferredValue(Generic[_T]): + func: Callable[[], _T] cache_value: bool - def __init__(self, func: Callable[..., Any], cache_value: bool = True) -> None: ... - def get_value(self) -> Any: ... + def __init__(self, func: Callable[[], _T], cache_value: bool = True) -> None: ... + def get_value(self) -> _T: ... def __int__(self) -> int: ... def __float__(self) -> float: ... def __unicode__(self) -> str: ... diff --git a/stubs/boltons/boltons/listutils.pyi b/stubs/boltons/boltons/listutils.pyi index b1036a93d7da..89f9b122e092 100644 --- a/stubs/boltons/boltons/listutils.pyi +++ b/stubs/boltons/boltons/listutils.pyi @@ -1,26 +1,23 @@ from collections.abc import Iterable -from typing import SupportsIndex, TypeVar, overload +from typing import SupportsIndex, TypeVar from typing_extensions import Self, TypeAlias _T = TypeVar("_T") class BarrelList(list[_T]): lists: list[list[_T]] - @overload - def __init__(self, iterable: None = None) -> None: ... - @overload - def __init__(self, iterable: Iterable[_T]) -> None: ... + def __init__(self, iterable: Iterable[_T] | None = None) -> None: ... def insert(self, index: SupportsIndex, item: _T) -> None: ... def append(self, item: _T) -> None: ... def extend(self, iterable: Iterable[_T]) -> None: ... def pop(self, *a) -> _T: ... - def iter_slice(self, start: int, stop: int, step: int | None = None) -> Iterable[_T]: ... + def iter_slice(self, start: int | None, stop: int | None, step: int | None = None) -> Iterable[_T]: ... def del_slice(self, start: int, stop: int, step: int | None = None) -> None: ... __delslice__ = del_slice @classmethod def from_iterable(cls, it: Iterable[_T]) -> Self: ... def __getslice__(self, start: int, stop: int): ... - def __setslice__(self, start: int, stop: int, sequence: int) -> None: ... + def __setslice__(self, start: SupportsIndex, stop: SupportsIndex, sequence: Iterable[_T]) -> None: ... def sort(self) -> None: ... # type: ignore[override] def reverse(self) -> None: ... def count(self, item: _T) -> int: ... @@ -30,4 +27,4 @@ BList: TypeAlias = BarrelList[_T] class SplayList(list[_T]): def shift(self, item_index: int, dest_index: int = 0) -> None: ... - def swap(self, item_index: int, dest_index: int) -> None: ... + def swap(self, item_index: SupportsIndex, dest_index: SupportsIndex) -> None: ... diff --git a/stubs/boltons/boltons/mathutils.pyi b/stubs/boltons/boltons/mathutils.pyi index 2590a3e50b45..e74ca0e8d2fe 100644 --- a/stubs/boltons/boltons/mathutils.pyi +++ b/stubs/boltons/boltons/mathutils.pyi @@ -1,8 +1,15 @@ -from collections.abc import Sequence +from collections.abc import Iterable +from typing import overload def clamp(x: float, lower: float = ..., upper: float = ...) -> float: ... -def ceil(x: float, options: Sequence[float] | None = None) -> float: ... -def floor(x: float, options: Sequence[float] | None = None) -> float: ... +@overload +def ceil(x: float, options: None = None) -> int: ... +@overload +def ceil(x: float, options: Iterable[float]) -> float: ... +@overload +def floor(x: float, options: None = None) -> int: ... +@overload +def floor(x: float, options: Iterable[float]) -> float: ... class Bits: val: int diff --git a/stubs/boltons/boltons/mboxutils.pyi b/stubs/boltons/boltons/mboxutils.pyi index ca61fb7008dd..5d1019c9be16 100644 --- a/stubs/boltons/boltons/mboxutils.pyi +++ b/stubs/boltons/boltons/mboxutils.pyi @@ -1,8 +1,17 @@ import mailbox +from _typeshed import StrPath +from collections.abc import Callable +from typing import IO, Any DEFAULT_MAXMEM: int class mbox_readonlydir(mailbox.mbox): maxmem: int - def __init__(self, path: str, factory: type | None = None, create: bool = True, maxmem: int = 1048576) -> None: ... + def __init__( + self, + path: StrPath, + factory: Callable[[IO[Any]], mailbox.mboxMessage] | None = None, + create: bool = True, + maxmem: int = 1048576, + ) -> None: ... def flush(self) -> None: ... diff --git a/stubs/boltons/boltons/namedutils.pyi b/stubs/boltons/boltons/namedutils.pyi index 5d3f117f9784..c92f6bb870ca 100644 --- a/stubs/boltons/boltons/namedutils.pyi +++ b/stubs/boltons/boltons/namedutils.pyi @@ -1,4 +1,4 @@ -from collections.abc import Sequence +from collections.abc import Iterable -def namedtuple(typename: str, field_names: Sequence[str], verbose: bool = False, rename: bool = False): ... -def namedlist(typename: str, field_names: Sequence[str], verbose: bool = False, rename: bool = False): ... +def namedtuple(typename: str, field_names: str | Iterable[str], verbose: bool = False, rename: bool = False): ... +def namedlist(typename: str, field_names: str | Iterable[str], verbose: bool = False, rename: bool = False): ... diff --git a/stubs/boltons/boltons/pathutils.pyi b/stubs/boltons/boltons/pathutils.pyi index ecb8004b8771..58d9d4c934b6 100644 --- a/stubs/boltons/boltons/pathutils.pyi +++ b/stubs/boltons/boltons/pathutils.pyi @@ -1,5 +1,7 @@ +from _typeshed import StrPath + def augpath( - path: str, + path: StrPath, suffix: str = "", prefix: str = "", ext: str | None = None, @@ -7,5 +9,5 @@ def augpath( dpath: str | None = None, multidot: bool = False, ) -> str: ... -def shrinkuser(path: str, home: str = "~") -> str: ... -def expandpath(path: str) -> str: ... +def shrinkuser(path: StrPath, home: str = "~") -> str: ... +def expandpath(path: StrPath) -> str: ... diff --git a/stubs/boltons/boltons/setutils.pyi b/stubs/boltons/boltons/setutils.pyi index 9926b6fa7caa..97dc8004bc5a 100644 --- a/stubs/boltons/boltons/setutils.pyi +++ b/stubs/boltons/boltons/setutils.pyi @@ -1,8 +1,13 @@ -from collections.abc import Generator, Iterable, Iterator, MutableSet +from collections.abc import Collection, Container, Generator, Iterable, Iterator, MutableSet from itertools import islice -from typing import Any +from typing import Any, Literal, Protocol, SupportsIndex, TypeVar, overload from typing_extensions import Self +_T_co = TypeVar("_T_co", covariant=True) + +class _RSub(Iterable[_T_co], Protocol): + def __new__(cls: type[_RSub[_T_co]], param: list[_T_co], /) -> _RSub[_T_co]: ... + class IndexedSet(MutableSet[Any]): item_index_map: dict[Any, Any] item_list: list[Any] @@ -13,20 +18,20 @@ class IndexedSet(MutableSet[Any]): def __iter__(self) -> Iterator[Any]: ... def __reversed__(self) -> Generator[Any, None, None]: ... @classmethod - def from_iterable(cls, it: Iterable[Any]) -> set[Any]: ... + def from_iterable(cls, it: Iterable[Any]) -> Self: ... def add(self, item: Any) -> None: ... def remove(self, item: Any) -> None: ... def discard(self, item: Any) -> None: ... def clear(self) -> None: ... def isdisjoint(self, other: Iterable[Any]) -> bool: ... - def issubset(self, other: Iterable[Any]) -> bool: ... - def issuperset(self, other: Iterable[Any]) -> bool: ... - def union(self, *others: Iterable[Any]) -> set[Any]: ... - def iter_intersection(self, *others: Iterable[Any]) -> Generator[Any, None, None]: ... - def intersection(self, *others: Iterable[Any]) -> set[Any]: ... + def issubset(self, other: Collection[Any]) -> bool: ... + def issuperset(self, other: Collection[Any]) -> bool: ... + def union(self, *others: Iterable[Any]) -> Self: ... + def iter_intersection(self, *others: Container[Any]) -> Generator[Any, None, None]: ... + def intersection(self, *others: Container[Any]) -> Self: ... def iter_difference(self, *others: Iterable[Any]) -> Generator[Any, None, None]: ... - def difference(self, *others: Iterable[Any]) -> Any: ... - def symmetric_difference(self, *others: Iterable[Any]) -> set[Any]: ... + def difference(self, *others: Iterable[Any]) -> Self: ... + def symmetric_difference(self, *others: Container[Any]) -> Self: ... # __or__ = union __ror__ = union # __and__ = intersection @@ -34,56 +39,61 @@ class IndexedSet(MutableSet[Any]): # __sub__ = difference # __xor__ = symmetric_difference __rxor__ = symmetric_difference - def __rsub__(self, other: Iterable[Any]) -> Any: ... + def __rsub__(self, other: _RSub[_T_co]) -> _RSub[_T_co]: ... def update(self, *others: Iterable[Any]) -> None: ... def intersection_update(self, *others: Iterable[Any]) -> None: ... - def difference_update(self, *others: Iterable[Any]) -> None: ... + def difference_update(self, *others: Container[Any]) -> None: ... def symmetric_difference_update(self, other: Iterable[Any]) -> None: ... def iter_slice(self, start: int, stop: int, step: int | None = None) -> islice[Iterable[Any]]: ... - def __getitem__(self, index: int) -> Any: ... + @overload + def __getitem__(self, index: slice) -> Self: ... + @overload + def __getitem__(self, index: SupportsIndex) -> Any: ... def pop(self, index: int | None = None) -> Any: ... - def count(self, val: Any) -> int: ... + def count(self, val: Any) -> Literal[0, 1]: ... def reverse(self) -> None: ... def sort(self, **kwargs) -> None: ... def index(self, val: Any) -> int: ... -def complement(wrapped: set[Any]) -> set[Any]: ... +def complement(wrapped: Iterable[Any]) -> _ComplementSet: ... class _ComplementSet: - def __init__(self, included: set[Any] | None = None, excluded: set[Any] | None = None) -> None: ... - def complemented(self) -> set[Any]: ... + def __init__( + self, included: set[Any] | frozenset[Any] | None = None, excluded: set[Any] | frozenset[Any] | None = None + ) -> None: ... + def complemented(self) -> _ComplementSet: ... __invert__ = complemented def complement(self) -> None: ... def __contains__(self, item: Any) -> bool: ... def add(self, item: Any) -> None: ... def remove(self, item: Any) -> None: ... def pop(self) -> Any: ... - def intersection(self, other: set[Any]) -> set[Any]: ... - def __and__(self, other: set[Any]) -> set[Any]: ... + def intersection(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... + def __and__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... __rand__ = __and__ - def __iand__(self, other: set[Any]) -> Self: ... - def union(self, other: set[Any]) -> set[Any]: ... - def __or__(self, other: set[Any]) -> set[Any]: ... + def __iand__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> Self: ... + def union(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... + def __or__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... __ror__ = __or__ - def __ior__(self, other: set[Any]) -> Self: ... + def __ior__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> Self: ... def update(self, items: Iterable[Any]) -> None: ... def discard(self, items: Iterable[Any]) -> None: ... - def symmetric_difference(self, other: set[Any]) -> set[Any]: ... - def __xor__(self, other: set[Any]) -> set[Any]: ... + def symmetric_difference(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... + def __xor__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... __rxor__ = __xor__ - def symmetric_difference_update(self, other: set[Any]) -> None: ... - def isdisjoint(self, other: set[Any]) -> bool: ... - def issubset(self, other: set[Any]) -> bool: ... - def __le__(self, other: set[Any]) -> bool: ... - def __lt__(self, other: set[Any]) -> bool: ... - def issuperset(self, other: set[Any]) -> bool: ... - def __ge__(self, other: set[Any]) -> bool: ... - def __gt__(self, other: set[Any]) -> bool: ... - def difference(self, other: set[Any]) -> set[Any]: ... - def __sub__(self, other: set[Any]) -> set[Any]: ... - def __rsub__(self, other: set[Any]) -> set[Any]: ... - def difference_update(self, other: set[Any]) -> None: ... - def __isub__(self, other: set[Any]) -> Self: ... + def symmetric_difference_update(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> None: ... + def isdisjoint(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> bool: ... + def issubset(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> bool: ... + def __le__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> bool: ... + def __lt__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> bool: ... + def issuperset(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> bool: ... + def __ge__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> bool: ... + def __gt__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> bool: ... + def difference(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... + def __sub__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... + def __rsub__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> _ComplementSet: ... + def difference_update(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> None: ... + def __isub__(self, other: set[Any] | frozenset[Any] | _ComplementSet) -> Self: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[Any]: ... def __bool__(self) -> bool: ... diff --git a/stubs/boltons/boltons/statsutils.pyi b/stubs/boltons/boltons/statsutils.pyi index 5697064a971c..544252e03fd2 100644 --- a/stubs/boltons/boltons/statsutils.pyi +++ b/stubs/boltons/boltons/statsutils.pyi @@ -1,6 +1,7 @@ -from _typeshed import Incomplete -from collections.abc import Callable, Iterator -from typing import Any +from _typeshed import ConvertibleToFloat, Incomplete +from collections.abc import Callable, Iterable, Iterator +from typing import Any, Literal, overload +from typing_extensions import Self class _StatsProperty: name: str @@ -8,12 +9,22 @@ class _StatsProperty: internal_name: str __doc__: str | None def __init__(self, name: str, func: Callable[..., Any]) -> None: ... - def __get__(self, obj: object, objtype: Any | None = None) -> Any: ... + @overload + def __get__(self, obj: None, objtype: object = None) -> Self: ... + @overload + def __get__(self, obj: Stats, objtype: object = None) -> float: ... class Stats: data: list[float] default: float - def __init__(self, data: list[float], default: float = 0.0, use_copy: bool = True, is_sorted: bool = False) -> None: ... + @overload + def __init__(self, data: list[float], default: float = 0.0, *, use_copy: Literal[False], is_sorted: bool = False) -> None: ... + @overload + def __init__(self, data: list[float], default: float, use_copy: Literal[False], is_sorted: bool = False) -> None: ... + @overload + def __init__( + self, data: Iterable[float], default: float = 0.0, use_copy: Literal[True] = True, is_sorted: bool = False + ) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[float]: ... def clear_cache(self) -> None: ... @@ -32,18 +43,18 @@ class Stats: skewness: _StatsProperty kurtosis: _StatsProperty pearson_type: _StatsProperty - def get_quantile(self, q: float) -> float: ... + def get_quantile(self, q: ConvertibleToFloat) -> float: ... def get_zscore(self, value: float) -> float: ... def trim_relative(self, amount: float = 0.15) -> None: ... - def get_histogram_counts(self, bins: int | None = None, **kw) -> int: ... - def format_histogram(self, bins: int | None = None, **kw) -> str: ... + def get_histogram_counts(self, bins: int | list[float] | None = None, **kw) -> list[tuple[float, int]]: ... + def format_histogram(self, bins: int | list[float] | None = None, **kw) -> str: ... def describe( - self, quantiles: list[float] | None = None, format: str | None = None - ) -> dict[str, float] | list[float] | str: ... + self, quantiles: Iterable[float] | None = None, format: str | None = None + ) -> dict[str, float] | list[tuple[str, float]] | str: ... def describe( - data: list[float], quantiles: list[float] | None = None, format: str | None = None -) -> dict[str, float] | list[float] | str: ... + data: Iterable[float], quantiles: Iterable[float] | None = None, format: str | None = None +) -> dict[str, float] | list[tuple[str, float]] | str: ... mean: Incomplete median: Incomplete diff --git a/stubs/boltons/boltons/strutils.pyi b/stubs/boltons/boltons/strutils.pyi index 6a25d9278d36..f39ea8d3b456 100644 --- a/stubs/boltons/boltons/strutils.pyi +++ b/stubs/boltons/boltons/strutils.pyi @@ -1,15 +1,19 @@ -from collections.abc import Callable, Generator, Iterable +from _typeshed import ReadableBuffer +from collections.abc import Callable, Generator, Iterable, Sized from html.parser import HTMLParser -from typing import Any, TypeVar - -_KT = TypeVar("_KT") -_VT = TypeVar("_VT") +from re import Pattern +from typing import Literal, overload def camel2under(camel_string: str) -> str: ... def under2camel(under_string: str) -> str: ... -def slugify(text: str, delim: str = "_", lower: bool = True, ascii: bool = False) -> str: ... -def split_punct_ws(text: str) -> str: ... -def unit_len(sized_iterable: Iterable[Any], unit_noun: str = "item") -> str: ... +@overload +def slugify(text: str, delim: str = "_", lower: bool = True, *, ascii: Literal[True]) -> bytes: ... +@overload +def slugify(text: str, delim: str, lower: bool, ascii: Literal[True]) -> bytes: ... +@overload +def slugify(text: str, delim: str = "_", lower: bool = True, ascii: Literal[False] = False) -> str: ... +def split_punct_ws(text: str) -> list[str]: ... +def unit_len(sized_iterable: Sized, unit_noun: str = "item") -> str: ... def ordinalize(number: int | str, ext_only: bool = False) -> str: ... def cardinalize(unit_noun: str, count: int) -> str: ... def singularize(word: str) -> str: ... @@ -17,12 +21,11 @@ def pluralize(word: str) -> str: ... def find_hashtags(string: str) -> list[str]: ... def a10n(string: str) -> str: ... def strip_ansi(text: str) -> str: ... -def asciify(text: str, ignore: bool = False): ... +def asciify(text: str | bytes | bytearray, ignore: bool = False) -> bytes: ... def is_ascii(text: str) -> bool: ... -class DeaccenterDict(dict[_KT, _VT]): - def __missing__(self, key: _KT) -> _VT: ... - def __getitem__(self, key: _KT) -> _VT: ... +class DeaccenterDict(dict[int, int]): + def __missing__(self, key: int) -> int: ... def bytes2human(nbytes: int, ndigits: int = 0) -> str: ... @@ -37,14 +40,14 @@ class HTMLTextExtractor(HTMLParser): def get_text(self) -> str: ... def html2text(html: str) -> str: ... -def gunzip_bytes(bytestring: bytes) -> bytes: ... -def gzip_bytes(bytestring: bytes, level: int = 6) -> int: ... +def gunzip_bytes(bytestring: ReadableBuffer) -> bytes: ... +def gzip_bytes(bytestring: ReadableBuffer, level: int = 6) -> int: ... def iter_splitlines(text: str) -> Generator[str, None, None]: ... -def indent(text: str, margin: str, newline: str = "\n", key: Callable[..., bool] = ...) -> str: ... +def indent(text: str, margin: str, newline: str = "\n", key: Callable[[str], bool] = ...) -> str: ... def is_uuid(obj, version: int = 4) -> bool: ... -def escape_shell_args(args: list[str], sep: str = " ", style: str | None = None) -> str: ... -def args2sh(args: list[str], sep: str = " ") -> str: ... -def args2cmd(args: list[str], sep: str = " ") -> str: ... +def escape_shell_args(args: Iterable[str], sep: str = " ", style: Literal["cmd", "sh"] | None = None) -> str: ... +def args2sh(args: Iterable[str], sep: str = " ") -> str: ... +def args2cmd(args: Iterable[str], sep: str = " ") -> str: ... def parse_int_list(range_string: str, delim: str = ",", range_delim: str = "-") -> list[int]: ... def format_int_list(int_list: list[int], delim: str = ",", range_delim: str = "-", delim_space: bool = False) -> str: ... def complement_int_list( @@ -54,10 +57,10 @@ def int_ranges_from_int_list(range_string: str, delim: str = ",", range_delim: s class MultiReplace: group_map: dict[str, str] - combined_pattern: str + combined_pattern: Pattern[str] def __init__(self, sub_map: dict[str, str], **kwargs) -> None: ... def sub(self, text: str) -> str: ... def multi_replace(text: str, sub_map: dict[str, str], **kwargs) -> str: ... -def unwrap_text(text: str, ending: str = "\n\n") -> str: ... +def unwrap_text(text: str, ending: str | None = "\n\n") -> str: ... def removeprefix(text: str, prefix: str) -> str: ... diff --git a/stubs/boltons/boltons/tbutils.pyi b/stubs/boltons/boltons/tbutils.pyi index b0129b623748..6548787bb96f 100644 --- a/stubs/boltons/boltons/tbutils.pyi +++ b/stubs/boltons/boltons/tbutils.pyi @@ -1,6 +1,6 @@ -from collections.abc import Iterator +from collections.abc import Iterable, Iterator, Mapping from types import FrameType, TracebackType -from typing import Any +from typing import Any, Generic, Literal, TypeVar from typing_extensions import Self class Callpoint: @@ -13,7 +13,7 @@ class Callpoint: def __init__( self, module_name: str, module_path: str, func_name: str, lineno: int, lasti: int, line: str | None = None ) -> None: ... - def to_dict(self) -> dict[str, object]: ... + def to_dict(self) -> dict[str, Any]: ... @classmethod def from_current(cls, level: int = 1) -> Self: ... @classmethod @@ -22,29 +22,33 @@ class Callpoint: def from_tb(cls, tb: TracebackType) -> Self: ... def tb_frame_str(self) -> str: ... -class TracebackInfo: - callpoint_type: type[Callpoint] - frames: list[FrameType] - def __init__(self, frames: list[FrameType]) -> None: ... +_CallpointT = TypeVar("_CallpointT", bound=Callpoint, covariant=True, default=Callpoint) + +class TracebackInfo(Generic[_CallpointT]): + callpoint_type: type[_CallpointT] + frames: list[_CallpointT] + def __init__(self, frames: list[_CallpointT]) -> None: ... @classmethod def from_frame(cls, frame: FrameType | None = None, level: int = 1, limit: int | None = None) -> Self: ... @classmethod def from_traceback(cls, tb: TracebackType | None = None, limit: int | None = None) -> Self: ... @classmethod - def from_dict(cls, d: dict[str, list[FrameType]]) -> Self: ... - def to_dict(self) -> dict[str, list[FrameType]]: ... + def from_dict(cls, d: Mapping[Literal["frames"], list[_CallpointT]]) -> Self: ... + def to_dict(self) -> dict[str, list[dict[str, _CallpointT]]]: ... def __len__(self) -> int: ... - def __iter__(self) -> Iterator[FrameType]: ... + def __iter__(self) -> Iterator[_CallpointT]: ... def get_formatted(self) -> str: ... -class ExceptionInfo: - tb_info_type: type[TracebackInfo] +_TracebackInfoT = TypeVar("_TracebackInfoT", bound=TracebackInfo, covariant=True, default=TracebackInfo) + +class ExceptionInfo(Generic[_TracebackInfoT]): + tb_info_type: type[_TracebackInfoT] exc_type: str exc_msg: str - tb_info: TracebackInfo - def __init__(self, exc_type: str, exc_msg: str, tb_info: TracebackInfo) -> None: ... + tb_info: _TracebackInfoT + def __init__(self, exc_type: str, exc_msg: str, tb_info: _TracebackInfoT) -> None: ... @classmethod - def from_exc_info(cls, exc_type: str, exc_value: Any, traceback: TracebackType) -> Self: ... + def from_exc_info(cls, exc_type: type[BaseException], exc_value: BaseException, traceback: TracebackType) -> Self: ... @classmethod def from_current(cls) -> Self: ... def to_dict(self) -> dict[str, str | dict[str, list[FrameType]]]: ... @@ -62,19 +66,25 @@ class ContextualCallpoint(Callpoint): def from_tb(cls, tb: TracebackType) -> Self: ... def to_dict(self) -> dict[str, Any]: ... -class ContextualTracebackInfo(TracebackInfo): +class ContextualTracebackInfo(TracebackInfo[ContextualCallpoint]): callpoint_type: type[ContextualCallpoint] -class ContextualExceptionInfo(ExceptionInfo): +class ContextualExceptionInfo(ExceptionInfo[ContextualTracebackInfo]): tb_info_type: type[ContextualTracebackInfo] -def print_exception(etype: str, value: Any, tb: TracebackType, limit: int | None = None, file: str | None = None) -> None: ... +def print_exception( + etype: type[BaseException] | None, + value: BaseException | None, + tb: TracebackType | None, + limit: int | None = None, + file: str | None = None, +) -> None: ... class ParsedException: exc_type: str exc_msg: str frames: list[FrameType] - def __init__(self, exc_type_name: str, exc_msg: str, frames: list[FrameType] | None = None) -> None: ... + def __init__(self, exc_type_name: str, exc_msg: str, frames: Iterable[Mapping[str, Any]] | None = None) -> None: ... @property def source_file(self) -> str | None: ... def to_dict(self) -> dict[str, str | list[FrameType]]: ... diff --git a/stubs/boltons/boltons/timeutils.pyi b/stubs/boltons/boltons/timeutils.pyi index 4a31ab396675..68ab72b1a765 100644 --- a/stubs/boltons/boltons/timeutils.pyi +++ b/stubs/boltons/boltons/timeutils.pyi @@ -34,9 +34,9 @@ EPOCH_AWARE: datetime class LocalTZInfo(tzinfo): def is_dst(self, dt: datetime) -> bool: ... - def utcoffset(self, dt: datetime | None) -> timedelta: ... - def dst(self, dt: datetime | None) -> timedelta: ... - def tzname(self, dt: datetime | None) -> str: ... + def utcoffset(self, dt: datetime) -> timedelta: ... # type: ignore[override] # Doesn't support None + def dst(self, dt: datetime) -> timedelta: ... # type: ignore[override] # Doesn't support None + def tzname(self, dt: datetime) -> str: ... # type: ignore[override] # Doesn't support None LocalTZ: LocalTZInfo DSTSTART_2007: datetime