Skip to content
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

Making functions/methods subscriptable #1410

Open
Gobot1234 opened this issue Jun 9, 2023 · 0 comments
Open

Making functions/methods subscriptable #1410

Gobot1234 opened this issue Jun 9, 2023 · 0 comments
Labels
topic: feature Discussions about new features for Python's type annotations

Comments

@Gobot1234
Copy link
Contributor

Gobot1234 commented Jun 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: feature Discussions about new features for Python's type annotations
Projects
None yet
Development

No branches or pull requests

1 participant