René's URL Explorer Experiment


Title: Add a stdlib decorator that copies/applies the ParameterSpec from one function to another · Issue #107001 · python/cpython · GitHub

Open Graph Title: Add a stdlib decorator that copies/applies the ParameterSpec from one function to another · Issue #107001 · python/cpython

X Title: Add a stdlib decorator that copies/applies the ParameterSpec from one function to another · Issue #107001 · python/cpython

Description: Feature or enhancement Add an decorator that copies the parameter specs from one function onto another: Example implementation from collections.abc import Callable from typing import ParamSpec, TypeVar, cast, Any P = ParamSpec("P") T = T...

Open Graph Description: Feature or enhancement Add an decorator that copies the parameter specs from one function onto another: Example implementation from collections.abc import Callable from typing import ParamSpec, Typ...

X Description: Feature or enhancement Add an decorator that copies the parameter specs from one function onto another: Example implementation from collections.abc import Callable from typing import ParamSpec, Typ...

Opengraph URL: https://github.com/python/cpython/issues/107001

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add a stdlib decorator that copies/applies the ParameterSpec from one function to another","articleBody":"# Feature or enhancement\n\nAdd an decorator that copies the parameter specs from one function onto another:\n\n[Example implementation](https://stackoverflow.com/questions/71968447)\n```python\nfrom collections.abc import Callable\nfrom typing import ParamSpec, TypeVar, cast, Any\n\n\nP = ParamSpec(\"P\")\nT = TypeVar(\"T\")\n\n\ndef copy_kwargs(\n    kwargs_call: Callable[P, Any]\n) -> Callable[[Callable[..., T]], Callable[P, T]]:\n    \"\"\"Decorator does nothing but returning the casted original function\"\"\"\n\n    @wraps(kwargs_call)\n    def return_func(func: Callable[..., T]) -> Callable[P, T]:\n        return cast(Callable[P, T], func)\n\n    return return_func\n```\n\nAlternative names of `copy_kwargs` could be `apply_parameters`\n\n\n# Pitch\n\nA quite common pattern in Python is to create a new function `enhanced` that enhanced a given function `original` or method and passes arguments using `*args, **kwargs`.\nThis way the signature of `original` can be adopted without changing the signature of `enhanced`.\nThat is especially useful if you enhance a 3rd party function.\n\nA downside of this pattern is, that static type checkers (and IDE) are unable to detect if the correct parameters were used or give type/autocomplete hints.\n\nAdding this pattern allows static type checkers and IDE to give correct parameter hints and check them.\n\n# Previous discussion\nDiscussed with @ambv at a Sprint within Europython 2023\n\n# Specification\n\nThis function is very simple, so adding it every project that requires it would be very simple.\nA reason to add it to the standard library is that type checkers can/should check, that the applied parameter spec matches the one of the function.\n\nIn example:\n\n```python\n# Our test function for kwargs\ndef source_func(foo: str, bar: int, default: bool = True) -> str:\n    if not default:\n        return \"Not Default!\"\n    return f\"{foo}_{bar}\"\n\n@copy_kwargs(source_func)\ndef kwargs_test(**kwargs) -> float:\n    print(source_func(**kwargs))\n    return 1.2\n\nkwargs_test(\"a\", 2) # raises a TypeError but does not produce any TypingError atm\n```\n\nBut if `source_func` would be defined as\n```python\ndef source_func(*, foo: str, bar: int, default: bool = True) -> str:\n    ...\n```\n\nThe type checker would complain.\n\nSo I would suggest that type checkers check if the wrapped functions signature is compatible to the sourced function signature.\nWhich is separate discussion from including it into the stdlib.\n\nThe documentation should include a hint, that `*args` and `**kwargs` should be always added to the applied function.\n\n## Related Discourse Threads: \u003ca href=\"#sources\" id=\"sources\">#\u003c/a>\n\n- [Add a `same_definition_as_in`](https://discuss.python.org/t/add-a-same-definition-as-in/40135)\n- [Taking the argument signature from a different function](https://discuss.python.org/t/taking-the-argument-signature-from-a-different-function/42618)\n- [Proposal: Add `bound` to `ParamSpec`](https://discuss.python.org/t/proposal-add-bound-to-paramspec/39979)\n- [Precise typing of kwargs but without a TypedDict](https://discuss.python.org/t/precise-typing-of-kwargs-but-without-a-typeddict/49902)\n- [Extract kwargs types from a function signature](https://discuss.python.org/t/extract-kwargs-types-from-a-function-signature/34238)\n- [Dynamically building ParamSpecs from callables](https://discuss.python.org/t/dynamically-building-paramspecs-from-callables/17442)\n\n## Related Issues:\n\n- [How should we annotate functions that forward to their superclass?](https://github.com/python/typing/issues/1471) python/typing#1471 by @NeilGirdhar\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-121693\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/CarliJoy","@type":"Person","name":"CarliJoy"},"datePublished":"2023-07-22T10:45:44Z","url":"https://github.com/python/cpython/issues/107001"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:cf1a6009-e00c-b470-7ea7-5a365404adf6
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8FB4:1390B0:25D6B:32467:6B00176B
html-safe-nonce5779d865f622205b9bbf27cf8863c7602db6e87c5db7364ac4b46e53c1a2af4a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkI0OjEzOTBCMDoyNUQ2QjozMjQ2Nzo2QjAwMTc2QiIsInZpc2l0b3JfaWQiOiI2ODUwMDAzMDg5NzUyMDY5OTk1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaca47160946d515d5acaf714a3884e19cae38235dc39f559b00f48caa8adecb4a8
hovercard-subject-tagissue:1816719344
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/107001/issue_layout
twitter:imagehttps://opengraph.githubassets.com/bbb044749df176709967b5899e72ba80d9b88a2cb0113fb46e50afc4b1e27207/python/cpython/issues/107001
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/bbb044749df176709967b5899e72ba80d9b88a2cb0113fb46e50afc4b1e27207/python/cpython/issues/107001
og:image:altFeature or enhancement Add an decorator that copies the parameter specs from one function onto another: Example implementation from collections.abc import Callable from typing import ParamSpec, Typ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameCarliJoy
hostnamegithub.com
expected-hostnamegithub.com
Nonea2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release70121d4e855ee0bb7b75cf15d061d91f8863c0f8
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/107001#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F107001
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F107001
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/107001
Reloadhttps://github.com/python/cpython/issues/107001
Reloadhttps://github.com/python/cpython/issues/107001
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/107001
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/107001
Add a stdlib decorator that copies/applies the ParameterSpec from one function to anotherhttps://github.com/python/cpython/issues/107001#top
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-typinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-typing%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/CarliJoy
CarliJoyhttps://github.com/CarliJoy
on Jul 22, 2023https://github.com/python/cpython/issues/107001#issue-1816719344
Example implementationhttps://stackoverflow.com/questions/71968447
@ambvhttps://github.com/ambv
#https://github.com/python/cpython/issues/107001#sources
Add a same_definition_as_inhttps://discuss.python.org/t/add-a-same-definition-as-in/40135
Taking the argument signature from a different functionhttps://discuss.python.org/t/taking-the-argument-signature-from-a-different-function/42618
Proposal: Add bound to ParamSpechttps://discuss.python.org/t/proposal-add-bound-to-paramspec/39979
Precise typing of kwargs but without a TypedDicthttps://discuss.python.org/t/precise-typing-of-kwargs-but-without-a-typeddict/49902
Extract kwargs types from a function signaturehttps://discuss.python.org/t/extract-kwargs-types-from-a-function-signature/34238
Dynamically building ParamSpecs from callableshttps://discuss.python.org/t/dynamically-building-paramspecs-from-callables/17442
How should we annotate functions that forward to their superclass?https://github.com/python/typing/issues/1471
How should we annotate functions that forward to their superclass? typing#1471https://github.com/python/typing/issues/1471
@NeilGirdharhttps://github.com/NeilGirdhar
gh-107001: Add a stdlib decorator that copies/applies the ParameterSpec from one function to another #121693https://github.com/python/cpython/pull/121693
CarliJoyhttps://github.com/CarliJoy
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on Jul 22, 2023https://github.com/python/cpython/issues/107001#event-9890920462
https://github.com/CarliJoy
CarliJoyhttps://github.com/CarliJoy
on Jul 22, 2023https://github.com/python/cpython/issues/107001#issuecomment-1646568060
https://github.com/AlexWaygood
AlexWaygoodhttps://github.com/AlexWaygood
on Jul 22, 2023https://github.com/python/cpython/issues/107001#issuecomment-1646569384
AlexWaygoodhttps://github.com/AlexWaygood
topic-typinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-typing%22
on Jul 22, 2023https://github.com/python/cpython/issues/107001#event-9891024969
AlexWaygoodhttps://github.com/AlexWaygood
on Jul 22, 2023https://github.com/python/cpython/issues/107001#event-9891036501
AlexWaygoodhttps://github.com/AlexWaygood
on Jul 22, 2023https://github.com/python/cpython/issues/107001#event-9891037328
AlexWaygoodhttps://github.com/AlexWaygood
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Jul 22, 2023https://github.com/python/cpython/issues/107001#event-9891037637
https://github.com/CarliJoy
CarliJoyhttps://github.com/CarliJoy
on Jul 13, 2024https://github.com/python/cpython/issues/107001#issuecomment-2226918319
https://github.com/CarliJoy
CarliJoyhttps://github.com/CarliJoy
on Jul 13, 2024https://github.com/python/cpython/issues/107001#issuecomment-2226937673
mypy playhttps://mypy-play.net/?mypy=1.2.0&python=3.12&gist=c3b42203864d5a70b65acaef2c8c24d4
pyright playhttps://pyright-play.net/?code=GYJw9gtgBAxmA28CmMAuBLMA7AzgOgEMAjGKdCABzBFSgGEDFjkBYAKFEilQE8L0sAczKVqtABTso0qAEEsPADRSZdbDAKokWTUmVsZUADLotIRvsMAFAuYgBlCiksyAKnyQA1Wy%2BkacqL5QYABuSCDw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V227toWIEPebniKDZDg0N0ORJop3hom2ZNG0HRI5DKNo7Wp3nUzksKBNA043NA0U-98RszF-NDeLR7S4jyDDDLgnvSr4bpF97DE4DpOpEg4hczzzzRA7bAwCmOBMmifUnr9evU0kDJYmA0TiLW8DAE0AtjcLfmi3DZuy8gyMSaMja1pjac43l4J2VA%2BOE997B%2By5TIAEIjSHu5JEkAimM3se4sA6RFzIcfAHgwC9Q2vXiF9hj06tTPiEHeAs-rNOR9HQn-iJ3zDOBioLOFnNYNzvMxyehh94nYMQ1DqewybHFq0oCOZ0g2eo7nUnKzxN8nhrU09zdJcFZNJx9wHr1WeYcgaLxjgQY2703pWwtrAj8H0mb2zXE7ZIrtp7ALnuHcBCxUEu3JvXEAeAPb71wQkZ2ZMnDiEIaPYhu9PZuTISTShbsg60KwWA8EUdvbZCAA
https://github.com/Ravencentric
Ravencentrichttps://github.com/Ravencentric
on Jul 14, 2024https://github.com/python/cpython/issues/107001#issuecomment-2227355743
https://github.com/CarliJoy
CarliJoyhttps://github.com/CarliJoy
on Jul 14, 2024https://github.com/python/cpython/issues/107001#issuecomment-2227432220
working on MyPy Playhttps://mypy-play.net/?mypy=1.2.0&python=3.12&gist=348812a4390cacb8ac689a34beb6960d
working on MyPy Playhttps://mypy-play.net/?mypy=1.10.1&python=3.12&gist=0929871f4680a70533a13c1b71387da2
https://github.com/Ravencentric
Ravencentrichttps://github.com/Ravencentric
on Jul 14, 2024https://github.com/python/cpython/issues/107001#issuecomment-2227448892
https://discuss.python.org/t/precise-typing-of-kwargs-but-without-a-typeddict/49902https://discuss.python.org/t/precise-typing-of-kwargs-but-without-a-typeddict/49902
https://discuss.python.org/t/extract-kwargs-types-from-a-function-signature/34238https://discuss.python.org/t/extract-kwargs-types-from-a-function-signature/34238
https://discuss.python.org/t/dynamically-building-paramspecs-from-callables/17442https://discuss.python.org/t/dynamically-building-paramspecs-from-callables/17442
https://github.com/CarliJoy
CarliJoyhttps://github.com/CarliJoy
on Mar 11, 2025https://github.com/python/cpython/issues/107001#issuecomment-2715752518
PR #121693https://github.com/python/cpython/pull/121693
numberhttps://github.com/python/cpython/pull/121693#issuecomment-2585436053
ofhttps://github.com/python/cpython/issues/107001#sources
similar questionshttps://stackoverflow.com/q/71968447/3813064
typing.python.orghttps://typing.python.org/en/latest/
@AlexWaygoodhttps://github.com/AlexWaygood
@JelleZijlstrahttps://github.com/JelleZijlstra
PR #121693https://github.com/python/cpython/pull/121693
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/107001
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/107001
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
topic-typinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-typing%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.