-
Notifications
You must be signed in to change notification settings - Fork 266
Open
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations
Description
I'd like to make both instances and the types of functions and methods (including builtin methods) subscriptable.
Part of this proposal has been discussed already on python-ideas (https://discuss.python.org/t/making-functions-subscriptable-at-runtime/26463) but I thought it might also be worthwhile making FunctionType
etc. subscriptable and work in a similar way to Callable
just with extra descriptor behaviour that binds it into a MethodType
.
class Foo:
bar: FunctionType[[Self, int], str]
# equivalent to
def bar(self, arg1, /) -> str: ...
This is different from Callable
as if FunctionType
was replaced with Callable
, bar
would always require a self argument.
This unfortunately probably requires special casing in type checkers as it isn't quite currently possible with PEP 612 (ParamSpec + Concatenate) (see #946) unless the PEP is updated
Metadata
Metadata
Assignees
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations