Title: Proposal: signature copying for kwargs. · Issue #270 · python/typing · GitHub
Open Graph Title: Proposal: signature copying for kwargs. · Issue #270 · python/typing
X Title: Proposal: signature copying for kwargs. · Issue #270 · python/typing
Description: There's a quite common pattern in python code which is: def function(foo, *args, **kwargs): # do something with foo other_function(*args, **kwargs) # possibly do something else def other_function(color: str=..., temperature: float=..., s...
Open Graph Description: There's a quite common pattern in python code which is: def function(foo, *args, **kwargs): # do something with foo other_function(*args, **kwargs) # possibly do something else def other_function(c...
X Description: There's a quite common pattern in python code which is: def function(foo, *args, **kwargs): # do something with foo other_function(*args, **kwargs) # possibly do something else def other_functi...
Opengraph URL: https://github.com/python/typing/issues/270
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: signature copying for kwargs.","articleBody":"There's a quite common pattern in python code which is:\n\n``` python\ndef function(foo, *args, **kwargs):\n # do something with foo\n other_function(*args, **kwargs)\n # possibly do something else\n\ndef other_function(color: str=..., temperature: float=..., style: Stylesheet=..., timeout: Optional[int]=..., database_adaptor: Adaptor=..., strict: bool=..., output: IO[str], allow_frogs: bool=..., mode: SomeEnum=...):\n # do something with a lot of options\n```\n\n(a usual subcase of this one is when `other_function` is actually `super().function` ). This presents two problems for a static analyzer:\n- the call from `function` to `other_function` can not be type-checked properly because of the `*args, **kwargs` in the call arguments.\n- there is no sensible way to annotate `function`, so calls to it are unchecked.\n\nThe problem for me also affects readability of the code (which is for me one of the main problems that annotations tries to address). James Powell from numfocus even gave a pydata talk about the difficulties it brings at https://www.youtube.com/watch?v=MQMbnhSthZQ\n\nEven if theoretically the args/kwargs packing feature of python can be used with more or less arbitrary data, IMO this use-case is common enough to warrant some special treatment. I was thinking on a way to flag this usage, for example:\n\n```\n@delegate_args(other_function)\ndef function(foo, *args, **kwargs):\n other_function(*args, **kwargs)\n```\n\nThis could hint an analyzer so:\n- On calls to `function`, the \"extra\" arguments are checked to match the signature of `other_function`\n- The call to other_function is considered valid given that it uses the same arguments (I know that the code above could have modified the content of kwargs, but it's still more checking than what we have now).\n\nFor me, even without static analyzer, the readability benefits of seeing\n\n```\n@delegate_args(matplotlib.pyplot.plot)\ndef plot_valuation(ticker_symbol: str, start: date, end: date, *args, **kwargs): ...\n```\n\nand knowing that `plot_valuation` accepts any valid arguments from matplotlib's plot function, is worth it.\n","author":{"url":"https://github.com/dmoisset","@type":"Person","name":"dmoisset"},"datePublished":"2016-08-26T16:55:21Z","url":"https://github.com/python/typing/issues/270"}
| 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:3b4087ee-3e02-89c2-5da4-fcea9e5bbad1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BD5E:1DA187:29B0A07:36A1BD7:6B000A11 |
| html-safe-nonce | 36eb78ad49cb4a90012f1a980f862d22c2664f174b8a49028d4511aa8bc7477f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDVFOjFEQTE4NzoyOUIwQTA3OjM2QTFCRDc6NkIwMDBBMTEiLCJ2aXNpdG9yX2lkIjoiNzI5NTEyMTUwNDQ2NTg0ODg0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3a58c879984dbf783ed8950118bed6d8acb8a1dcfaf03f0aebd74324ac1d13d2 |
| hovercard-subject-tag | issue:173497307 |
| 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/270/issue_layout |
| twitter:image | https://opengraph.githubassets.com/61d2dbd5d3f83a2bc96425929d428a377a399cf7b9010dbbd30e8ee4dad7e0af/python/typing/issues/270 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/61d2dbd5d3f83a2bc96425929d428a377a399cf7b9010dbbd30e8ee4dad7e0af/python/typing/issues/270 |
| og:image:alt | There's a quite common pattern in python code which is: def function(foo, *args, **kwargs): # do something with foo other_function(*args, **kwargs) # possibly do something else def other_function(c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dmoisset |
| 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