|
| 1 | +from collections.abc import Callable |
| 2 | +from contextvars import Context |
| 3 | +from types import FrameType, TracebackType |
| 4 | +from typing import Any, Protocol, overload |
| 5 | +from typing_extensions import Literal, TypeAlias |
| 6 | + |
| 7 | +_TraceEvent: TypeAlias = Literal["switch", "throw"] |
| 8 | +_TraceCallback: TypeAlias = Callable[[_TraceEvent, tuple[greenlet, greenlet]], object] |
| 9 | + |
| 10 | +CLOCKS_PER_SEC: int |
| 11 | +GREENLET_USE_CONTEXT_VARS: bool |
| 12 | +GREENLET_USE_GC: bool |
| 13 | +GREENLET_USE_STANDARD_THREADING: bool |
| 14 | +GREENLET_USE_TRACING: bool |
| 15 | +# this is a PyCapsule, it may be used to pass the gevent C-API to another C-extension |
| 16 | +# there isn't a runtime type for this, since it's only an opaque wrapper around void* |
| 17 | +# but it's probably still better than pretending it doesn't exist, so people that need |
| 18 | +# to pass this around, can still pass it around without having to ignore type errors... |
| 19 | +_C_API: object |
| 20 | + |
| 21 | +class _ParentDescriptor(Protocol): |
| 22 | + def __get__(self, obj: greenlet, owner: type[greenlet] | None = None) -> greenlet | None: ... |
| 23 | + def __set__(self, obj: greenlet, value: greenlet) -> None: ... |
| 24 | + |
| 25 | +class GreenletExit(BaseException): ... |
| 26 | +class error(Exception): ... |
| 27 | + |
| 28 | +class greenlet: |
| 29 | + @property |
| 30 | + def dead(self) -> bool: ... |
| 31 | + @property |
| 32 | + def gr_context(self) -> Context | None: ... |
| 33 | + @gr_context.setter |
| 34 | + def gr_context(self, value: Context | None) -> None: ... |
| 35 | + @property |
| 36 | + def gr_frame(self) -> FrameType | None: ... |
| 37 | + # the parent attribute is a bit special, since it can't be set to `None` manually, but |
| 38 | + # it can be `None` for the master greenlet which will always be around, regardless of |
| 39 | + # how many greenlets have been spawned explicitly. Since there can only be one such |
| 40 | + # greenlet per thread, there is no way to create another one manually. |
| 41 | + parent: _ParentDescriptor |
| 42 | + @property |
| 43 | + def run(self) -> Callable[..., Any]: ... |
| 44 | + @run.setter |
| 45 | + def run(self, value: Callable[..., Any]) -> None: ... |
| 46 | + def __init__(self, run: Callable[..., Any] | None = None, parent: greenlet | None = None) -> None: ... |
| 47 | + def switch(self, *args: Any, **kwargs: Any) -> Any: ... |
| 48 | + @overload |
| 49 | + def throw( |
| 50 | + self, __typ: type[BaseException] = ..., __val: BaseException | object = None, __tb: TracebackType | None = None |
| 51 | + ) -> Any: ... |
| 52 | + @overload |
| 53 | + def throw(self, __typ: BaseException = ..., __val: None = None, __tb: TracebackType | None = None) -> Any: ... |
| 54 | + def __bool__(self) -> bool: ... |
| 55 | + |
| 56 | + # aliases for some module attributes/methods |
| 57 | + GreenletExit: type[GreenletExit] |
| 58 | + error: type[error] |
| 59 | + @staticmethod |
| 60 | + def getcurrent() -> greenlet: ... |
| 61 | + @staticmethod |
| 62 | + def gettrace() -> _TraceCallback | None: ... |
| 63 | + @staticmethod |
| 64 | + def settrace(__callback: _TraceCallback | None) -> _TraceCallback | None: ... |
| 65 | + |
| 66 | +def enable_optional_cleanup(__enabled: bool) -> None: ... |
| 67 | +def get_clocks_used_doing_optional_cleanup() -> int: ... |
| 68 | +def get_pending_cleanup_count() -> int: ... |
| 69 | +def get_total_main_greenlets() -> int: ... |
| 70 | +def get_tstate_trash_delete_nesting() -> int: ... |
| 71 | +def getcurrent() -> greenlet: ... |
| 72 | +def gettrace() -> _TraceCallback | None: ... |
| 73 | +def set_thread_local(__key: object, __value: object) -> None: ... |
| 74 | +def settrace(__callback: _TraceCallback | None) -> _TraceCallback | None: ... |
0 commit comments