diff --git a/stubs/boltons/boltons/fileutils.pyi b/stubs/boltons/boltons/fileutils.pyi index 8e2fb8b75b27..c7ed18ef9bcb 100644 --- a/stubs/boltons/boltons/fileutils.pyi +++ b/stubs/boltons/boltons/fileutils.pyi @@ -1,6 +1,5 @@ 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, TypeVar, overload from typing_extensions import Never, Self @@ -9,7 +8,7 @@ _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: ... +def rotate_file(filename: StrPath, *, keep: int = 5) -> None: ... class FilePerms: user: str @@ -22,7 +21,7 @@ class FilePerms: def from_path(cls, path: StrOrBytesPath) -> Self: ... def __int__(self) -> int: ... -def atomic_save(dest_path: str, **kwargs) -> AtomicSaver: ... +def atomic_save(dest_path: StrPath, **kwargs) -> AtomicSaver: ... class AtomicSaver: dest_path: str @@ -37,10 +36,10 @@ class AtomicSaver: part_path: str mode: str open_flags: int - part_file: str | None - def __init__(self, dest_path: str, **kwargs) -> None: ... + part_file: IO[Any] | None + def __init__(self, dest_path: StrPath, **kwargs) -> None: ... def setup(self) -> None: ... - def __enter__(self) -> IO[Any] | None: ... + def __enter__(self) -> IO[Any]: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/stubs/boltons/boltons/queueutils.pyi b/stubs/boltons/boltons/queueutils.pyi index 83c6dd01e8a5..e6d2a4761613 100644 --- a/stubs/boltons/boltons/queueutils.pyi +++ b/stubs/boltons/boltons/queueutils.pyi @@ -1,16 +1,29 @@ -from typing import TypeAlias - -class BasePriorityQueue: - def __init__(self, **kw) -> None: ... - def add(self, task, priority: int | None = None) -> None: ... - def remove(self, task) -> None: ... - def peek(self, default=...): ... - def pop(self, default=...): ... +from collections.abc import Hashable +from typing import Any, Generic, TypeAlias, TypeVar, overload + +_TaskT = TypeVar("_TaskT", bound=Hashable, default=Any) +_DefaultT = TypeVar("_DefaultT") + +class BasePriorityQueue(Generic[_TaskT]): + def __init__(self, **kw: Any) -> None: ... + def add(self, task: _TaskT, priority: float | None = None) -> None: ... + def remove(self, task: _TaskT) -> None: ... + + @overload + def peek(self) -> _TaskT: ... + @overload + def peek(self, default: _DefaultT) -> _TaskT | _DefaultT: ... + + @overload + def pop(self) -> _TaskT: ... + @overload + def pop(self, default: _DefaultT) -> _TaskT | _DefaultT: ... + def __len__(self) -> int: ... -class HeapPriorityQueue(BasePriorityQueue): ... -class SortedPriorityQueue(BasePriorityQueue): ... +class HeapPriorityQueue(BasePriorityQueue[_TaskT]): ... +class SortedPriorityQueue(BasePriorityQueue[_TaskT]): ... -PriorityQueue: TypeAlias = SortedPriorityQueue +PriorityQueue: TypeAlias = SortedPriorityQueue[_TaskT] __all__ = ["PriorityQueue", "BasePriorityQueue", "HeapPriorityQueue", "SortedPriorityQueue"]