Skip to content

add pass_meta_key decorator#1807

Merged
davidism merged 2 commits intomasterfrom
pass-meta
Mar 5, 2021
Merged

add pass_meta_key decorator#1807
davidism merged 2 commits intomasterfrom
pass-meta

Conversation

@davidism
Copy link
Copy Markdown
Member

@davidism davidism commented Mar 5, 2021

Extensions using Context.meta can use pass_meta_key to create decorators for passing their data to callbacks. The doc_description parameter can be used to add a specific description of the object, so that the decorator's docs can be included in the extension's docs.

# in the extension
from click.decorators import pass_meta_key
pass_auth = pass_meta_key("click-auth.auth", doc_description="the :class:`ClickAuth` object")
# in the extension's docs
pass_auth.__doc__
Decorator that passes the :class:`ClickAuth` object as the first argument to the decorated function.
# in the user code
@pass_auth
def list_prs(auth):
    ...

Also changed docs config so typing information is shown next to parameter descriptions instead of in the signature. https://pallets-click--1807.org.readthedocs.build/en/1807/api/#click.decorators.pass_meta_key

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@davidism davidism added this to the 8.0.0 milestone Mar 5, 2021
@davidism davidism merged commit a6fea31 into master Mar 5, 2021
@davidism davidism deleted the pass-meta branch March 5, 2021 16:58
@eshaan7
Copy link
Copy Markdown

eshaan7 commented Mar 5, 2021

Really glad that you liked my idea. :D

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@pass_meta_key decorator

2 participants