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:
Grzegorz Bokota
2021-10-04 15:22:56 +02:00
committed by GitHub
parent 5ab72a0c48
commit c5658b353a
2 changed files with 23 additions and 0 deletions

View File

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

View File

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