|
1 | | -from typing import Any |
2 | 1 | from typing_extensions import Self |
| 2 | +from typing_extensions import TypeVar |
| 3 | +from typing_extensions import TypeVarTuple |
| 4 | +from typing_extensions import Unpack |
3 | 5 |
|
| 6 | +import asyncio |
| 7 | +import sys |
4 | 8 | from collections.abc import Callable |
5 | | -from signal import Signals |
| 9 | +from collections.abc import Generator |
| 10 | +from contextlib import contextmanager |
| 11 | +from types import TracebackType |
6 | 12 |
|
7 | 13 | from gi.repository import GLib |
8 | 14 |
|
9 | | -class GLibTask: |
10 | | - def __init__(self, *args: object, **kwargs: object) -> None: ... |
| 15 | +if sys.version_info >= (3, 14): |
| 16 | + from asyncio.events import _AbstractEventLoopPolicy |
| 17 | +else: |
| 18 | + from asyncio.events import AbstractEventLoopPolicy as _AbstractEventLoopPolicy |
| 19 | + |
| 20 | +_T_co = TypeVar("_T_co", covariant=True) |
| 21 | +_Ts = TypeVarTuple("_Ts") |
| 22 | + |
| 23 | +class GLibTask(asyncio.Task[_T_co]): |
11 | 24 | def set_priority(self, priority: int) -> None: ... |
12 | 25 | def get_priority(self) -> int: ... |
13 | 26 |
|
14 | | -class GLibEventLoop: |
15 | | - def __init__(self, main_context: GLib.MainContext) -> None: ... |
16 | | - def add_signal_handler( |
17 | | - self, |
18 | | - sig: Signals, |
19 | | - callback: Callable[..., Any], |
20 | | - *args: object, |
21 | | - ) -> None: ... |
22 | | - def remove_signal_handler(self, sig: Signals) -> bool: ... |
23 | | - def close(self) -> None: ... |
| 27 | +class _GLibEventLoopMixin: |
| 28 | + def __init__(self, main_context: GLib.MainContext | None) -> None: ... |
| 29 | + @contextmanager |
| 30 | + def paused(self) -> Generator[None]: ... |
| 31 | + @contextmanager |
| 32 | + def running(self, quit_func: Callable[[], object]) -> Generator[None]: ... |
| 33 | + def stop(self) -> None: ... |
| 34 | + def time(self) -> float: ... |
| 35 | + |
| 36 | +class _GLibEventLoopRunMixin: |
| 37 | + def run_forever(self) -> None: ... |
24 | 38 |
|
25 | | -class GLibEventLoopPolicy: |
| 39 | +if sys.platform == "win32": |
| 40 | + class GLibEventLoop( |
| 41 | + _GLibEventLoopMixin, _GLibEventLoopRunMixin, asyncio.ProactorEventLoop |
| 42 | + ): |
| 43 | + def __init__(self, main_context: GLib.MainContext | None = None) -> None: ... |
| 44 | + |
| 45 | +else: |
| 46 | + class GLibEventLoop( |
| 47 | + _GLibEventLoopMixin, _GLibEventLoopRunMixin, asyncio.SelectorEventLoop |
| 48 | + ): |
| 49 | + def __init__(self, main_context: GLib.MainContext | None = None) -> None: ... |
| 50 | + def add_signal_handler( |
| 51 | + self, |
| 52 | + sig: int, |
| 53 | + callback: Callable[[Unpack[_Ts]], object], |
| 54 | + *args: Unpack[_Ts], |
| 55 | + ) -> None: ... |
| 56 | + def remove_signal_handler(self, sig: int) -> bool: ... |
| 57 | + def close(self) -> None: ... |
| 58 | + |
| 59 | +class GLibEventLoopPolicy(_AbstractEventLoopPolicy): |
26 | 60 | def __init__(self) -> None: ... |
27 | 61 | def __enter__(self) -> Self: ... |
28 | | - def __exit__(self, exc_type, exc_value, traceback) -> None: ... |
| 62 | + def __exit__( |
| 63 | + self, |
| 64 | + exc_type: type[BaseException] | None, |
| 65 | + exc_value: BaseException | None, |
| 66 | + traceback: TracebackType | None, |
| 67 | + ) -> None: ... |
29 | 68 | def get_event_loop(self) -> GLibEventLoop: ... |
30 | 69 | def get_event_loop_for_context(self, ctx: GLib.MainContext) -> GLibEventLoop: ... |
31 | | - def set_event_loop(self, loop: GLibEventLoop) -> None: ... |
| 70 | + def set_event_loop(self, loop: asyncio.AbstractEventLoop | None) -> None: ... |
| 71 | + def new_event_loop(self) -> GLibEventLoop: ... |
| 72 | + |
| 73 | + if sys.platform != "win32" and sys.version_info < (3, 12): |
| 74 | + def get_child_watcher(self) -> asyncio.AbstractChildWatcher: ... |
0 commit comments