mirror of
https://github.com/ihabunek/toot.git
synced 2025-02-02 15:07:51 -05:00
Fix typing not to break older python versions
This commit is contained in:
parent
b9aae37e7d
commit
a8aeb32e18
1
setup.py
1
setup.py
@ -59,6 +59,7 @@ setup(
|
|||||||
"pytest-xdist[psutil]",
|
"pytest-xdist[psutil]",
|
||||||
"setuptools",
|
"setuptools",
|
||||||
"vermin",
|
"vermin",
|
||||||
|
"typing-extensions",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
entry_points={
|
entry_points={
|
||||||
|
@ -2,11 +2,18 @@ import click
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import typing as t
|
||||||
|
|
||||||
from click.testing import Result
|
from click.testing import Result
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from toot import App, User, config, __version__
|
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"]
|
PRIVACY_CHOICES = ["public", "unlisted", "private"]
|
||||||
@ -17,7 +24,7 @@ seconds" or any combination of above. Shorthand: "1d", "2h30m", "5m30s\""""
|
|||||||
|
|
||||||
|
|
||||||
# Type alias for run commands
|
# Type alias for run commands
|
||||||
Run = Callable[..., Result]
|
Run = t.Callable[..., Result]
|
||||||
|
|
||||||
|
|
||||||
def get_default_visibility() -> str:
|
def get_default_visibility() -> str:
|
||||||
@ -39,23 +46,18 @@ CONTEXT = dict(
|
|||||||
|
|
||||||
|
|
||||||
# Data object to add to Click context
|
# Data object to add to Click context
|
||||||
class Context(NamedTuple):
|
class Context(t.NamedTuple):
|
||||||
app: Optional[App]
|
app: t.Optional[App]
|
||||||
user: Optional[User] = None
|
user: t.Optional[User] = None
|
||||||
color: bool = False
|
color: bool = False
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
quiet: bool = False
|
quiet: bool = False
|
||||||
|
|
||||||
|
|
||||||
P = ParamSpec("P")
|
def pass_context(f: "t.Callable[te.Concatenate[Context, P], R]") -> "t.Callable[P, R]":
|
||||||
R = TypeVar("R")
|
|
||||||
T = TypeVar("T")
|
|
||||||
|
|
||||||
|
|
||||||
def pass_context(f: Callable[Concatenate[Context, P], R]) -> Callable[P, R]:
|
|
||||||
"""Pass `obj` from click context as first argument."""
|
"""Pass `obj` from click context as first argument."""
|
||||||
@wraps(f)
|
@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()
|
ctx = click.get_current_context()
|
||||||
return f(ctx.obj, *args, **kwargs)
|
return f(ctx.obj, *args, **kwargs)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user