diff --git a/setup.cfg b/setup.cfg index 80536bf1..7e93847d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -91,6 +91,7 @@ python = deps = coverage pytest + pytest-mypy-plugins; python_version >= "3.9" install_command = python -m pip install --no-binary coverage {opts} {packages} commands = diff --git a/src/wrapt/__init__.pyi b/src/wrapt/__init__.pyi new file mode 100644 index 00000000..0014104f --- /dev/null +++ b/src/wrapt/__init__.pyi @@ -0,0 +1,5 @@ +from typing import Callable, TypeVar + +F = TypeVar("F", bound=Callable) + +def FunctionWrapper(wrapped: F, wrapper: Callable) -> F: ... diff --git a/src/wrapt/py.typed b/src/wrapt/py.typed new file mode 100644 index 00000000..b648ac92 --- /dev/null +++ b/src/wrapt/py.typed @@ -0,0 +1 @@ +partial diff --git a/tests/test_mypy.yml b/tests/test_mypy.yml new file mode 100644 index 00000000..9dc5dba4 --- /dev/null +++ b/tests/test_mypy.yml @@ -0,0 +1,18 @@ +- case: function_wrapper + main: | + from wrapt import FunctionWrapper + + def x(a: bool, b: str) -> int: + return 1 + + def wrapper(*args, **kwargs): + pass + + x = FunctionWrapper(x, wrapper) + reveal_type(x) + + x(1, None) + out: | + main:10: note: Revealed type is "def (a: builtins.bool, b: builtins.str) -> builtins.int" + main:12: error: Argument 1 to "x" has incompatible type "int"; expected "bool" [arg-type] + main:12: error: Argument 2 to "x" has incompatible type "None"; expected "str" [arg-type]