Improve annotation around uccallback

This commit is contained in:
elicn
2022-10-20 14:17:43 +03:00
parent 647832b01b
commit d6e5e6a19f

View File

@@ -2,7 +2,7 @@
# based on Nguyen Anh Quynnh's work # based on Nguyen Anh Quynnh's work
from __future__ import annotations from __future__ import annotations
from typing import Any, Callable, Iterable, Iterator, Mapping, MutableMapping, Optional, Sequence, Tuple, Type, TypeVar from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator, Mapping, MutableMapping, Optional, Sequence, Tuple, Type, TypeVar
import ctypes import ctypes
import functools import functools
@@ -271,7 +271,12 @@ def debug() -> str:
return f'python-{all_archs}-c{lib_maj}.{lib_min}-b{bnd_maj}.{bnd_min}' return f'python-{all_archs}-c{lib_maj}.{lib_min}-b{bnd_maj}.{bnd_min}'
def uccallback(functype: Type[ctypes._FuncPointer]): if TYPE_CHECKING:
# _FuncPointer is not recognized at runtime; use it only for type annotation
_CFP = TypeVar('_CFP', bound=ctypes._FuncPointer)
def uccallback(functype: Type[_CFP]):
"""Unicorn callback decorator. """Unicorn callback decorator.
Wraps a Python function meant to be dispatched by Unicorn as a hook callback. Wraps a Python function meant to be dispatched by Unicorn as a hook callback.
@@ -281,7 +286,7 @@ def uccallback(functype: Type[ctypes._FuncPointer]):
If an exception occurs, it is saved to the Uc object and emulation is stopped. If an exception occurs, it is saved to the Uc object and emulation is stopped.
""" """
def decorate(func): def decorate(func) -> _CFP:
@functools.wraps(func) @functools.wraps(func)
def wrapper(uc: Uc, *args, **kwargs): def wrapper(uc: Uc, *args, **kwargs):