Skip to content

Commit

Permalink
Fix typing not to break older python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Dec 5, 2023
1 parent b9aae37 commit a8aeb32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"pytest-xdist[psutil]",
"setuptools",
"vermin",
"typing-extensions",
],
},
entry_points={
Expand Down
26 changes: 14 additions & 12 deletions toot/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
import logging
import os
import sys
import typing as t

from click.testing import Result
from functools import wraps
from toot import App, User, config, __version__
from typing import Callable, Concatenate, NamedTuple, Optional, ParamSpec, TypeVar

if t.TYPE_CHECKING:
import typing_extensions as te
P = te.ParamSpec("P")

R = t.TypeVar("R")
T = t.TypeVar("T")


PRIVACY_CHOICES = ["public", "unlisted", "private"]
Expand All @@ -17,7 +24,7 @@


# Type alias for run commands
Run = Callable[..., Result]
Run = t.Callable[..., Result]


def get_default_visibility() -> str:
Expand All @@ -39,23 +46,18 @@ def get_default_visibility() -> str:


# Data object to add to Click context
class Context(NamedTuple):
app: Optional[App]
user: Optional[User] = None
class Context(t.NamedTuple):
app: t.Optional[App]
user: t.Optional[User] = None
color: bool = False
debug: bool = False
quiet: bool = False


P = ParamSpec("P")
R = TypeVar("R")
T = TypeVar("T")


def pass_context(f: Callable[Concatenate[Context, P], R]) -> Callable[P, R]:
def pass_context(f: "t.Callable[te.Concatenate[Context, P], R]") -> "t.Callable[P, R]":
"""Pass `obj` from click context as first argument."""
@wraps(f)
def wrapped(*args: P.args, **kwargs: P.kwargs) -> R:
def wrapped(*args: "P.args", **kwargs: "P.kwargs") -> R:
ctx = click.get_current_context()
return f(ctx.obj, *args, **kwargs)

Expand Down

0 comments on commit a8aeb32

Please sign in to comment.