Add __slots__ to third-party packages using stubdefaulter (#14619)

This commit is contained in:
Jelle Zijlstra
2025-08-21 15:38:13 -07:00
committed by GitHub
parent 573b57d8da
commit ca44e4c45d
135 changed files with 675 additions and 25 deletions
@@ -4,6 +4,7 @@ from typing_extensions import Self
from gevent.hub import Hub
class AbstractLinkable:
__slots__ = ("hub", "_links", "_notifier", "_notify_all", "__weakref__")
@property
def hub(self) -> Hub | None: ...
def __init__(self, hub: Hub | None = None) -> None: ...
+2 -1
View File
@@ -28,7 +28,8 @@ class FlushingBufferedWriter(io.BufferedWriter): ...
class WriteallMixin:
def writeall(self, b: ReadableBuffer, /) -> int: ...
class FileIO(io.FileIO): ...
class FileIO(io.FileIO):
__slots__ = ()
class WriteIsWriteallMixin(WriteallMixin):
def write(self, b: ReadableBuffer, /) -> int: ...
+1
View File
@@ -3,6 +3,7 @@ from weakref import ref
@final
class ValuedWeakRef(ref):
__slots__ = ("value",)
value: Any
@final
+1
View File
@@ -19,6 +19,7 @@ def implementer(interface: Any, /) -> Callable[[_T], _T]: ...
class MonitorWarning(RuntimeWarning): ...
class _MonitorEntry:
__slots__ = ("function", "period", "last_run_time")
function: Callable[[Hub], object]
period: float
last_run_time: float
+1
View File
@@ -9,6 +9,7 @@ _Cookie = NewType("_Cookie", LockType)
class EmptyTimeout(Exception): ...
class Queue(Generic[_T]):
__slots__ = ("_queue", "_mutex", "_not_empty", "unfinished_tasks")
unfinished_tasks: int
def __init__(self) -> None: ...
def task_done(self) -> None: ...
+3 -1
View File
@@ -21,6 +21,7 @@ _ThrowArgs: TypeAlias = (
)
class Waiter(Generic[_T]):
__slots__ = ["hub", "greenlet", "value", "_exception"]
@property
def hub(self) -> Hub: ... # readonly in Cython
@property
@@ -42,4 +43,5 @@ class Waiter(Generic[_T]):
def __call__(self, source: _ValueSource[_T]) -> None: ...
@final
class MultipleWaiter(Waiter[_T]): ...
class MultipleWaiter(Waiter[_T]):
__slots__ = ["_values"]
+2
View File
@@ -20,6 +20,7 @@ class _ValueSource(Protocol[_T_co]):
def exception(self) -> BaseException | None: ...
class Event(AbstractLinkable):
__slots__ = ("_flag",)
def __init__(self) -> None: ...
def is_set(self) -> bool: ...
def isSet(self) -> bool: ...
@@ -32,6 +33,7 @@ class Event(AbstractLinkable):
def wait(self, timeout: float) -> bool: ...
class AsyncResult(AbstractLinkable, Generic[_T]):
__slots__ = ("_value", "_exc_info", "_imap_task_index")
def __init__(self) -> None: ...
@property
def value(self) -> _T | None: ...
+1
View File
@@ -105,6 +105,7 @@ class Hub(WaitOperationsGreenlet):
threadpool: _DefaultReturnProperty[ThreadPool]
class linkproxy:
__slots__ = ["callback", "obj"]
callback: Callable[[object], object]
obj: object
def __init__(self, callback: Callable[[_T], object], obj: _T) -> None: ...
+9
View File
@@ -2,6 +2,15 @@ from typing import Any
from typing_extensions import Self
class local:
__slots__ = (
"_local__impl",
"_local_type_set_descriptors",
"_local_type_get_descriptors",
"_local_type_vars",
"_local_type_del_descriptors",
"_local_type",
"_local_type_set_or_del_descriptors",
)
def __init__(self, *args: object, **kwargs: object) -> None: ...
def __copy__(self) -> Self: ...
def __getattribute__(self, name: str, /) -> Any: ...
+4 -1
View File
@@ -8,6 +8,7 @@ from gevent.hub import Hub
__all__ = ["Semaphore", "BoundedSemaphore", "DummySemaphore", "RLock"]
class Semaphore(AbstractLinkable):
__slots__ = ("counter", "_multithreaded")
counter: int
def __init__(self, value: int = 1, hub: Hub | None = None) -> None: ...
def acquire(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
@@ -18,7 +19,8 @@ class Semaphore(AbstractLinkable):
def __enter__(self) -> None: ...
def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
class BoundedSemaphore(Semaphore): ...
class BoundedSemaphore(Semaphore):
__slots__ = ("_initial_value",)
class DummySemaphore:
def __init__(self, value: int | None = None) -> None: ...
@@ -33,6 +35,7 @@ class DummySemaphore:
def __exit__(self, typ: type[BaseException] | None, val: BaseException | None, tb: TracebackType | None) -> None: ...
class RLock:
__slots__ = ("_block", "_owner", "_count", "__weakref__")
def __init__(self, hub: Hub | None = None) -> None: ...
def acquire(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
def __enter__(self) -> bool: ...
+1
View File
@@ -18,6 +18,7 @@ _S = TypeVar("_S")
_P = ParamSpec("_P")
class GroupMappingMixin:
__slots__ = ()
def spawn(self, func: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> Greenlet[_P, _T]: ...
# we would like to use ParamSpec for these, but since args and kwds are passed in as is
# pyright will complain if we use _P.args/_P.kwargs, it appears to work on mypy though
+14 -1
View File
@@ -23,6 +23,16 @@ class _LogOutputStream(SupportsWrite[str], Protocol):
def flush(self) -> None: ...
class Input:
__slots__ = (
"rfile",
"content_length",
"socket",
"position",
"chunked_input",
"chunk_length",
"_chunked_input_error",
"send_100_continue_enabled",
)
rfile: BufferedReader
content_length: int | None
socket: _GeventSocket | None
@@ -103,6 +113,7 @@ class WSGIHandler:
def get_environ(self) -> WSGIEnvironment: ...
class LoggingLogAdapter:
__slots__ = ("_logger", "_level")
def __init__(self, logger: Logger, level: int = 20) -> None: ...
def write(self, msg: str) -> None: ...
def flush(self) -> None: ...
@@ -111,9 +122,11 @@ class LoggingLogAdapter:
def __setattr__(self, name: str, value: object) -> None: ...
def __delattr__(self, name: str) -> None: ...
class Environ(WSGIEnvironment): ...
class Environ(WSGIEnvironment):
__slots__ = ()
class SecureEnviron(Environ):
__slots__ = ("secure_repr", "whitelist_keys", "print_masked_keys")
default_secure_repr: ClassVar[bool]
default_whitelist_keys: ClassVar[Container[str]]
default_print_masked_keys: ClassVar[bool]
+9 -2
View File
@@ -21,6 +21,7 @@ else:
_T = TypeVar("_T")
class SimpleQueue(Generic[_T]):
__slots__ = ("_maxsize", "getters", "putters", "hub", "_event_unlock", "queue", "__weakref__", "is_shutdown")
@property
def hub(self) -> Hub: ... # readonly in Cython
@property
@@ -53,6 +54,7 @@ class SimpleQueue(Generic[_T]):
next = __next__
class Queue(SimpleQueue[_T]):
__slots__ = ("_cond", "unfinished_tasks")
@property
def unfinished_tasks(self) -> int: ... # readonly in Cython
@overload
@@ -69,6 +71,7 @@ JoinableQueue = Queue
@final
class UnboundQueue(Queue[_T]):
__slots__ = ()
@overload
def __init__(self, maxsize: None = None) -> None: ...
@overload
@@ -76,10 +79,14 @@ class UnboundQueue(Queue[_T]):
@overload
def __init__(self, maxsize: None = None, *, items: Iterable[_T]) -> None: ...
class PriorityQueue(Queue[_T]): ...
class LifoQueue(Queue[_T]): ...
class PriorityQueue(Queue[_T]):
__slots__ = ()
class LifoQueue(Queue[_T]):
__slots__ = ()
class Channel(Generic[_T]):
__slots__ = ("getters", "putters", "hub", "_event_unlock", "__weakref__")
@property
def getters(self) -> deque[Waiter[Any]]: ... # readonly in Cython
@property
+12
View File
@@ -16,6 +16,17 @@ _TaskItem: TypeAlias = tuple[Callable[..., Any], tuple[Any, ...], dict[str, Any]
_Receiver: TypeAlias = Callable[[_ValueSource[_T]], object]
class ThreadPool(GroupMappingMixin):
__slots__ = (
"hub",
"_maxsize",
"manager",
"pid",
"fork_watcher",
"_available_worker_threads_greenlet_sem",
"_worker_greenlets",
"task_queue",
"_idle_task_timeout",
)
hub: Hub
pid: int
manager: Greenlet[..., Any] | None
@@ -37,6 +48,7 @@ class ThreadPool(GroupMappingMixin):
def spawn(self, func: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> AsyncResult[_T]: ... # type: ignore[override]
class ThreadResult(Generic[_T]):
__slots__ = ("exc_info", "async_watcher", "_call_when_ready", "value", "context", "hub", "receiver")
receiver: _Receiver[_T]
hub: Hub
context: object | None