Skip to content
Myr

Fix TypeVar for decorators that handle Commands

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The old type var would throw away the types of Callables. ``` import click @click.option("--name", prompt="Your name", help="The person to greet.") def hello(name: str) -> None: ... reveal_type(hello) # note: Revealed type is 'def (*Any, **Any) -> Any' ``` With this small adjustment mypy now knows that it's a `'def (name: builtins.str)'`

authored by David Euresti · committed by David Lord · parent 490ac01 · Browse files · 2 files+3 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+3 added−1 removed

  • other:+3 added−1 removed

2 files+3 added−1 removed

modified:src/click/decorators.py+1 added-1 removed
12 unmodified lines
13from .globals import get_current_context14from .utils import echo1516F = t.TypeVar("F", bound=t.Callable[..., t.Any])17FC = t.TypeVar("FC", t.Callable[..., t.Any], Command)17FC = t.TypeVar("FC", bound=t.Union[t.Callable[..., t.Any], Command])181920def pass_context(f: F) -> F:21 """Marks a callback as wanting to receive the current context
415 unmodified lines
modified:CHANGES.rst+2 added
5 unmodified lines
6Unreleased78- ``open_file`` recognizes ``Path("-")`` as a standard stream, the9 same as the string ``"-"``. :issue:`2106`10- The ``option`` and ``argument`` decorators preserve the type11 annotation of the decorated function. :pr:`2155`121314Version 8.0.315-------------
930 unmodified lines