-
Notifications
You must be signed in to change notification settings - Fork 29
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
Possible way to type hint callbacks #144
Comments
Its not about supporting 3.10 rather about not supporting everything that was before, except we cover everything with conditionals. Python 3.10 is now in debian stable i think we could drop everything else. Type hints are usually only used for CI and development, so i see no reason why people would need to run type checkers with old python versions. especially because type checkers have the option to specifically test against older python versions anyway |
Good, I will work on this |
While ParamSpec and Concatenate both are added to typing in 3.10, they exist in typing_extensions which is available for all Python versions since 3.7. |
Thanks for the info. I will use this then |
While with
The error doesn't make any sense to me, I suppose that it's not correct to use this method for this use case. |
Looks correct to me for the most part, the Also, if you don't care about type hinting for Python < 3.7, you could simply add from __future__ import annotations and replace: Optional[str] with the newer syntax without breaking compatibility: str | None |
It seems that the problem lays on from typing import Concatenate, ParamSpec, Callable
P = ParamSpec("P")
def func1(func: Callable[Concatenate[str, P], None], *args):
pass
def func2(a: str, b: str):
pass
func1(func2, "hello") This works from typing import Concatenate, ParamSpec, Callable, Optional
P = ParamSpec("P")
def func1(func: Optional[Callable[Concatenate[str, P], None]], *args): # Optional func here
pass
def func2(a: str, b: str):
pass
func1(func2, "hello") This not A bug in |
Yes probably. |
did you try other type checkers like for example pyright? |
With pyright works fine. In the PR I linked an issue that is similar. I have added some comments, let's see if someone is able to fix it |
The question for me is, you wrote the MR is blocked by that mypy issue. Personally for me thats not blocking, there exist at least one type checker who does it right. mypy has 2.4 k open issues, what if they never fix that issue? |
I see your point. Maybe let's wait some time to see if someone came up with a solution |
Yeah no hurry, your work, your MR, your decision :) |
Right now we hint all the callables that admits variable arguments as
Callable[..., T]
. Starting from python 3.10 we can use the combination ofConcatenate
andParamSpec
. Link to documentation.So for example
GAsyncReadyCallback
can be typed as@lovetox there are any plans to support 3.10?
The text was updated successfully, but these errors were encountered: