Title: Proposal: Generalize `Callable` to be able to specify argument names and kinds · Issue #264 · python/typing · GitHub
Open Graph Title: Proposal: Generalize `Callable` to be able to specify argument names and kinds · Issue #264 · python/typing
X Title: Proposal: Generalize `Callable` to be able to specify argument names and kinds · Issue #264 · python/typing
Description: Right now you can specify callables with two patterns of arguments (shown here by example): Callable[..., int] takes in any arguments, any number. Callable[[int, str, bool], int] takes in a predetermined number of required positional arg...
Open Graph Description: Right now you can specify callables with two patterns of arguments (shown here by example): Callable[..., int] takes in any arguments, any number. Callable[[int, str, bool], int] takes in a predete...
X Description: Right now you can specify callables with two patterns of arguments (shown here by example): Callable[..., int] takes in any arguments, any number. Callable[[int, str, bool], int] takes in a predete...
Opengraph URL: https://github.com/python/typing/issues/264
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Generalize `Callable` to be able to specify argument names and kinds","articleBody":"Right now you can specify callables with two patterns of arguments (shown here by example):\n- `Callable[..., int]` takes in any arguments, any number.\n- `Callable[[int, str, bool], int]` takes in a predetermined number of required positional arguments, none of which have names specified.\n\nThese don't cleanly match the actual types of callable objects in Python. Argument names, whether arguments are optional, and whether arguments are `*args` or `**kwargs` do affect the type of a callable. We should be able to spell these things in the type language. Doing so would enable us to correctly write the types of callback functions, for example.\n\nCallable should take two arguments: an _argument list_ and a _return type_. The return type is exactly as currently described in PEP484. The argument list is either:\n- `...`, indicating the function can take any arguments at all.\n- Square brackets around a comma separated series of _argument specifiers_ (_argspec_ for short), indicating particulars about the functions arguments\n\nAn _argument specifier_ is one of:\n- A bare type `TYP`. This has the same meaning as `Arg(TYP)`\n- `Arg(type, name=None)`, indicating a positional argument. If the name is specified, the argument must have that name.\n- `OptionalArg(type, name=None)`, indicating an optional positional argument. If the name is specified, the argument must have that name. (alternate name possibility `OptArg(type, name=None)`\n- `StarArg(type)`, indicating a \"star argument\" like `*args`\n- `KwArg(type)`, indicating a \"double star argument\" like `**kwargs`. (an alternate name here would be `Star2Arg(type)`.\n\nThe round parens are an indication that these are not actual _types_ but rather this new _argument specifier_ thing.\n\nLike the rules for python function arguments, all positional argspecs must come before all optional argspecs must come before zero or one star argspecs must come before zero or one kw argspecs. \n\nThis should be able to spell all function types you can make in python by defining single functions or methods, with the exception of functions that need `SelfType` to be properly specified, which is an orthogonal concern.\n\nSome statements I think are true:\n- `Callable[[Arg(T1, name='foo'), Arg(T2, name='bar')], R]` is a subtype of `Callable[[T1, T2], R]` \n- `Callable[[T1, OptionalArg(T2)], R]` is a subtype of `Callable[[T1], R]`\n- `Callable[[StarArg(T1)], R]` is a subtype of `Callable[[], R]` and is also a subtype of `Callable[[T1], R]` and is also a subtype of `Callable[[T1, T1], R]` and so on.\n- `Callable[[T1, StarArg(T1)], R]` is a subtype of `Callable[[T1], R]` and is also a subtype of `Callable[[T1, T1], R]` and so on, but is not a subtype of `Callable[[], R]`\n- If we want to be able to spell overloaded function types we'll need a specific way of combining callable types in the specific way overloading works; this proposal doesn't address that.\n","author":{"url":"https://github.com/sixolet","@type":"Person","name":"sixolet"},"datePublished":"2016-08-19T00:37:17Z","url":"https://github.com/python/typing/issues/264"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6141d0e3-4f40-5696-7daa-9ebf90245a7f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C48A:1A1C04:1827F84:20A6E56:6AFFF211 |
| html-safe-nonce | 0d89b65f6cebb8a7231d40eb5e11881e4fda39a07c0a76a29765dc1749e50471 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDhBOjFBMUMwNDoxODI3Rjg0OjIwQTZFNTY6NkFGRkYyMTEiLCJ2aXNpdG9yX2lkIjoiMzE2MTY0NjYxMDg4MzAxNTE4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6bd5716f4fbaddc18f3cb74b122baf6182cc631095c4cb41862dc987cd10c6e3 |
| hovercard-subject-tag | issue:172031574 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/typing/264/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ee8fed9189c41f9e3294d3c56d79be2cdfae020e7a82604791a75b4f5de15d0a/python/typing/issues/264 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ee8fed9189c41f9e3294d3c56d79be2cdfae020e7a82604791a75b4f5de15d0a/python/typing/issues/264 |
| og:image:alt | Right now you can specify callables with two patterns of arguments (shown here by example): Callable[..., int] takes in any arguments, any number. Callable[[int, str, bool], int] takes in a predete... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sixolet |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing git https://github.com/python/typing.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 24604008 |
| octolytics-dimension-repository_nwo | python/typing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24604008 |
| octolytics-dimension-repository_network_root_nwo | python/typing |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width