-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Multipe errors in the interaction between Protocol
, Callable
, ParamSpec
and TypeVar
#14079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
At the moment (as of mypy v1) the output of this is:
I'm not so sure about the |
The code above uses keyword arguments between The code above actually has a number of errors and missing import statements. To save others time, here's a fixed version of the code. from asyncio import AbstractEventLoop, get_event_loop
from functools import partial, wraps
from typing import Any, ParamSpec, Callable
_P = ParamSpec("_P")
def wrap(func: Callable[_P, Any]):
@wraps(func)
async def run(
loop: AbstractEventLoop | None = None,
executor: Any | None = None,
*args: _P.args,
**kwargs: _P.kwargs,
):
if loop is None:
loop = get_event_loop()
pfunc = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, pfunc)
return run |
Thanks for your input @erictraut , always appreciated.
https://peps.python.org/pep-0612/#id2 and https://peps.python.org/pep-0612/#concatenating-keyword-parameters are the sections that describe this in details. So it sounds like something that should be changed upstream in the I'll close this as I agree mypy likely doesn't need to try and support this use case as it is explicitly prohibited by PEP 612. |
(Not erroring on something not allowed is a bug, but not sure if an issue about that already exists: if not, you could make an issue about that specifically!) |
I recall that this is already logged elsewhere, but I can't find the exact bug number at the moment. |
Bug Report
I was trying to get some practice writing a stub with a complex Callable type. See the following wrapper function in
aiofiles.os
:If I'm not mistaken, the inline-typing should look something like this:
To Reproduce
Trying to do the following in a stub file:
Expected Behavior
I'm unsure, but I would like to see this being possible.
pyright actually gets the type of
stat_result
right, and gets wrapped callable type mostly right (it only loose the name of the generic arguments, but manages to keep bothloop
andexecutor
. Which idk if there's anything that can be done about that anyway)Actual Behavior
I get the following output:
Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: