Add type stubs for ensure_thread decorator (#23)

* types

* udpate manifest

* remove unused
This commit is contained in:
Talley Lambert
2021-09-11 07:59:24 -04:00
committed by GitHub
parent bb538cda2a
commit 06da62811b
6 changed files with 60 additions and 4 deletions

View File

@@ -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]

View File

@@ -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
View File

View 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): ...

View File

@@ -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:

View 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]]: ...