-
-
Notifications
You must be signed in to change notification settings - Fork 32k
ParamSpec
substitution: difference in behaviour between collections.abc.Callable
and typing.Callable
#102723
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
I am going to research, how hard it is to change. If this is a rather simple patch, I am going to apply it. Because parameters and their substitution is a very hard thing to get right. |
Wait, I am confused again. Why It seems like
Am I missing something? |
You're correct, Honestly, I think we should probably leave this one. The runtime allows all sorts of crazy things that should be rejected by type checkers. My personal favourite (we should make this an alias for >>> list[r"¯\_(ツ)_/¯"]
list['¯\\_(ツ)_/¯'] We've never promised that the runtime would disallow all things that should be rejected by type checkers, and I don't want us to start making that promise now. The fact that #88965 seems like a much more important issue to me, since that involves the runtime incorrectly raising a |
Yes, I agree. We should close this as won't fix. Because the correct behaviour is very complex to achieve. And will probably break other things.
There's no point to address a minor issue like this one by the cost of increasing code complexity. |
Would you be interested in taking a look at #88965? Serhiy assigned it to himself several months ago, but there's been no activity on the issue since, and it would be great to have it fixed. |
I will tomorrow! |
There is currently a difference in behaviour between
collections.abc.Callable
andtyping.Callable
for the following edge case involvingParamSpec
substitution:According to PEP-612, this is an invalid substitution, for two reasons:
ParamSpec
in a parameters list usingtyping(_extensions).Concatenate
.ParamSpec
in a parameters list is disallowed.As such, the behaviour of
collections.abc.Callable
is more correct here, so ideally we'd change the behaviour oftyping.Callable
to matchcollections.abc.Callable
.However, this error should hopefully be caught by static type checkers anyway, and this is a false negative rather than a false positive. The runtime makes no promises that it will raise
TypeError
on all invalid substitutions, so fixing this should be low priority, in my opinion. We should first concentrate on fixing substitutions where the runtime raises exceptions, even though it shouldn't. For example:This discrepancy in behaviour was first uncovered as part of a broader discussion in:
Cc. @sobolevn
The text was updated successfully, but these errors were encountered: