Bug Report
I have a decorator factory function that takes a schema and returns a decorator that validates something against the provided schema and also passes in an argument to the wrapped function. Here's a simplified version of the code:
fromtypingimportAny, Callable, Concatenate, ParamSpec, TypeVarP=ParamSpec("P")
Schema=TypeVar("Schema") Ret=TypeVar("Ret") defvalidate(
schema: Schema,
) ->Callable[
[Callable[Concatenate[int, P], Ret]],
Callable[P, Ret],
]:
defdecorator(
f: Callable[
Concatenate[int, P], Ret
]
) ->Callable[P, Ret]:
defwrap(*args: P.args, **kwargs: P.kwargs) ->Ret: # for simplicity, omitting schema validation # that would normally happen here.additional_arg=42# also simplifiedreturnf(additional_arg, *args, **kwargs)
returnwrapreturndecoratorWith mypy 1.1.1, the type annotations are fine. But with the recently released mypy 1.2.0, I get this error:
error: Incompatible return value type (got "Callable[[Arg(Callable[[int, **P], Ret], 'f')], Callable[P, Ret]]", expected "Callable[[Callable[[int, **P], Ret]], Callable[P, Ret]]") [return-value]
To Reproduce
Run the following with mypy 1.2.0 (example returns an error) and mypy 1.1.1 (no error):
Expected Behavior
I'd expect mypy to not return an error unless there is a legitimate issue with the types in this code (if that's the case, please let me know!).
Moreover, the actual type in the error message doesn't seem to be a valid type (specifically Arg(Callable[[int, **P], Ret], 'f') in this example).
Actual Behavior
error: Incompatible return value type (got "Callable[[Arg(Callable[[int, **P], Ret], 'f')], Callable[P, Ret]]", expected "Callable[[Callable[[int, **P], Ret]], Callable[P, Ret]]") [return-value]
Your Environment
- Mypy version used: 1.2.0
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini (and other config files): n/a - Python version used: 3.11
Bug Report
I have a decorator factory function that takes a schema and returns a decorator that validates something against the provided schema and also passes in an argument to the wrapped function. Here's a simplified version of the code:
With mypy 1.1.1, the type annotations are fine. But with the recently released mypy 1.2.0, I get this error:
To Reproduce
Run the following with mypy 1.2.0 (example returns an error) and mypy 1.1.1 (no error):
Expected Behavior
I'd expect mypy to not return an error unless there is a legitimate issue with the types in this code (if that's the case, please let me know!).
Moreover, the actual type in the error message doesn't seem to be a valid type (specifically
Arg(Callable[[int, **P], Ret], 'f')in this example).Actual Behavior
error: Incompatible return value type (got "Callable[[Arg(Callable[[int, **P], Ret], 'f')], Callable[P, Ret]]", expected "Callable[[Callable[[int, **P], Ret]], Callable[P, Ret]]") [return-value]Your Environment
mypy.ini(and other config files): n/a