mirror of
https://github.com/pyapp-kit/superqt.git
synced 2026-01-06 04:14:21 +01:00
Add type stubs for ensure_thread decorator (#23)
* types * udpate manifest * remove unused
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
include LICENSE
|
||||
include README.md
|
||||
|
||||
include superqt/py.typed
|
||||
recursive-include superqt *.py
|
||||
recursive-include superqt *.pyi
|
||||
recursive-exclude * __pycache__
|
||||
recursive-exclude * *.py[co]
|
||||
|
||||
@@ -66,6 +66,9 @@ testing =
|
||||
tox
|
||||
tox-conda
|
||||
|
||||
[options.package_data]
|
||||
superqt = py.typed
|
||||
|
||||
[flake8]
|
||||
exclude = _version.py,.eggs,examples
|
||||
docstring-convention = numpy
|
||||
|
||||
0
superqt/py.typed
Normal file
0
superqt/py.typed
Normal file
@@ -1,8 +1,7 @@
|
||||
from PyQt5.QtWidgets import QSlider
|
||||
from superqt.qtcompat.QtWidgets import QSlider
|
||||
|
||||
from ._generic_range_slider import _GenericRangeSlider
|
||||
from ._generic_slider import _GenericSlider
|
||||
from .qtcompat.QtWidgets import QSlider
|
||||
|
||||
class QDoubleRangeSlider(_GenericRangeSlider): ...
|
||||
class QDoubleSlider(_GenericSlider): ...
|
||||
|
||||
@@ -108,7 +108,7 @@ def _run_in_thread(
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
future = Future()
|
||||
future = Future() # type: ignore
|
||||
if thread is QThread.currentThread():
|
||||
result = func(*args, **kwargs)
|
||||
if not await_return:
|
||||
|
||||
52
superqt/utils/_ensure_thread.pyi
Normal file
52
superqt/utils/_ensure_thread.pyi
Normal file
@@ -0,0 +1,52 @@
|
||||
from concurrent.futures import Future
|
||||
from typing import Callable, TypeVar, overload
|
||||
|
||||
from typing_extensions import Literal, ParamSpec
|
||||
|
||||
P = ParamSpec("P")
|
||||
R = TypeVar("R")
|
||||
|
||||
@overload
|
||||
def ensure_main_thread(
|
||||
await_return: Literal[True],
|
||||
timeout: int = 1000,
|
||||
) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
|
||||
@overload
|
||||
def ensure_main_thread(
|
||||
func: Callable[P, R],
|
||||
await_return: Literal[True],
|
||||
timeout: int = 1000,
|
||||
) -> Callable[P, R]: ...
|
||||
@overload
|
||||
def ensure_main_thread(
|
||||
await_return: Literal[False] = False,
|
||||
timeout: int = 1000,
|
||||
) -> Callable[[Callable[P, R]], Callable[P, Future[R]]]: ...
|
||||
@overload
|
||||
def ensure_main_thread(
|
||||
func: Callable[P, R],
|
||||
await_return: Literal[False] = False,
|
||||
timeout: int = 1000,
|
||||
) -> Callable[P, Future[R]]: ...
|
||||
@overload
|
||||
def ensure_object_thread(
|
||||
await_return: Literal[True],
|
||||
timeout: int = 1000,
|
||||
) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
|
||||
@overload
|
||||
def ensure_object_thread(
|
||||
func: Callable[P, R],
|
||||
await_return: Literal[True],
|
||||
timeout: int = 1000,
|
||||
) -> Callable[P, R]: ...
|
||||
@overload
|
||||
def ensure_object_thread(
|
||||
await_return: Literal[False] = False,
|
||||
timeout: int = 1000,
|
||||
) -> Callable[[Callable[P, R]], Callable[P, Future[R]]]: ...
|
||||
@overload
|
||||
def ensure_object_thread(
|
||||
func: Callable[P, R],
|
||||
await_return: Literal[False] = False,
|
||||
timeout: int = 1000,
|
||||
) -> Callable[P, Future[R]]: ...
|
||||
Reference in New Issue
Block a user