Skip to content

Commit

Permalink
Make click.Context generic over obj
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Jan 6, 2024
1 parent cab9483 commit 343db57
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@
from .utils import PacifyFlushWrapper

if t.TYPE_CHECKING:
import typing_extensions as te

from .shell_completion import CompletionItem

ObjT = te.TypeVar("ObjT", default=t.Any)
else:
ObjT = t.TypeVar("ObjT")

F = t.TypeVar("F", bound="t.Callable[..., t.Any]")
V = t.TypeVar("V")

Expand Down Expand Up @@ -156,7 +162,7 @@ class ParameterSource(enum.Enum):
"""Used a prompt to confirm a default or provide a value."""


class Context:
class Context(t.Generic[ObjT]):
"""The context is a special internal object that holds state relevant
for the script execution at every single level. It's normally invisible
to commands unless they opt-in to getting access to it.
Expand Down Expand Up @@ -265,7 +271,7 @@ def __init__(
command: Command,
parent: Context | None = None,
info_name: str | None = None,
obj: t.Any | None = None,
obj: ObjT | None = None,
auto_envvar_prefix: str | None = None,
default_map: cabc.MutableMapping[str, t.Any] | None = None,
terminal_width: int | None = None,
Expand Down Expand Up @@ -302,7 +308,7 @@ def __init__(
obj = parent.obj

#: the user object stored.
self.obj: t.Any = obj
self.obj: ObjT | None = obj
self._meta: dict[str, t.Any] = getattr(parent, "meta", {})

#: A dictionary (-like object) with defaults for parameters.
Expand Down

0 comments on commit 343db57

Please sign in to comment.