don't state that type[Callable] is invalid#2207
don't state that type[Callable] is invalid#2207KotlinIsland wants to merge 1 commit intopython:mainfrom
type[Callable] is invalid#2207Conversation
hauntsaninja
left a comment
There was a problem hiding this comment.
Hm, Callable is definitely considered a special form. What are you hoping to use type[Callable] for?
why would it be considered a special form? i don't see it as any different to a class like
i have run into problems where type checkers have given incorrect errors because |
It is listed specifically in https://typing.python.org/en/latest/spec/annotations.html#type-and-annotation-expressions . It's special because it can be parameterized differently from other classes, though perhaps ParamSpec means its specialness can be reduced. |
|
I think it's also important to mention that Callable is very much not a normal class in the standard library: https://github.com/python/cpython/blob/b28e5f58ebf8d9badcc893cd189cb1575d4e3614/Lib/typing.py#L2830 and in typeshed: https://github.com/python/typeshed/blob/07ffb67b924d5f532f8b8b72a4902f58faae6aca/stdlib/typing.pyi#L236 |
I don't think that this point, specifically, is a very strong argument against this change. While it's true that I find the fact that If we want to consider |
@JelleZijlstra this is true, i will split this change to address these two separate concerns:
if we use a parameter spec, when what specialization remains? to me it seems non-special at that point
@AlexWaygood what are the unique semantics? and why can it not be expressed as a |
type[Callable] is invalid and don't refer to it as a special formtype[Callable] is invalid
f24fe27 to
2705b53
Compare
96bbf7c to
5b32801
Compare
5b32801 to
99648b3
Compare
see: https://discuss.python.org/t/callable-isnt-a-special-form/106407
there is no reason to disallow
type[Callable], i can understand the motivation for disallowingtype[Literal[1]](although i disagree with it), i can't see any reason whytype[Callable]isn't allowed whentype[tuple[int]]isthis is true regardless of whether or not
Callableis a special form (it's not, see #2214)motivation:
type[Callable]special form astral-sh/ruff#23753