mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-07-21 12:11:07 +02:00
Propagate function name in ensure_main_thread
and ensure_object_thread
(#28)
* propagate function name in decorators * add __wrapped__ information for inspect module
This commit is contained in:
@@ -61,6 +61,10 @@ def ensure_main_thread(
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
if hasattr(func, "__name__"):
|
||||
_func.__name__ = func.__name__
|
||||
_func.__wrapped__ = func
|
||||
|
||||
return _func
|
||||
|
||||
if func is None:
|
||||
@@ -93,6 +97,10 @@ def ensure_object_thread(
|
||||
func, self.thread(), await_return, timeout, self, *args, **kwargs
|
||||
)
|
||||
|
||||
if hasattr(func, "__name__"):
|
||||
_func.__name__ = func.__name__
|
||||
_func.__wrapped__ = func
|
||||
|
||||
return _func
|
||||
|
||||
if func is None:
|
||||
|
@@ -184,3 +184,18 @@ def test_main_thread_return(qtbot):
|
||||
with qtbot.wait_signal(t.finished):
|
||||
t.start()
|
||||
assert t.executed
|
||||
|
||||
|
||||
def test_names(qtbot):
|
||||
ob = SampleObject()
|
||||
assert ob.check_object_thread.__name__ == "check_object_thread"
|
||||
assert ob.check_object_thread_return.__name__ == "check_object_thread_return"
|
||||
assert (
|
||||
ob.check_object_thread_return_timeout.__name__
|
||||
== "check_object_thread_return_timeout"
|
||||
)
|
||||
assert (
|
||||
ob.check_object_thread_return_future.__name__
|
||||
== "check_object_thread_return_future"
|
||||
)
|
||||
assert ob.check_main_thread_return.__name__ == "check_main_thread_return"
|
||||
|
Reference in New Issue
Block a user