Skip to content

Commit de1755b

Browse files
emmatypingJelleZijlstra
authored andcommitted
Remove type cycle in click (#2277)
1 parent 41e5fe4 commit de1755b

File tree

4 files changed

+42
-44
lines changed

4 files changed

+42
-44
lines changed

third_party/2and3/click/core.pyi

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ from typing import (
1717

1818
from click.formatting import HelpFormatter
1919
from click.parser import OptionParser
20-
from click.types import ParamType, _ConvertibleType
21-
2220

2321
def invoke_param_callback(
2422
callback: Callable[['Context', 'Parameter', Optional[str]], Any],
@@ -313,12 +311,50 @@ class CommandCollection(MultiCommand):
313311
...
314312

315313

314+
class _ParamType:
315+
name: str
316+
is_composite: bool
317+
envvar_list_splitter: Optional[str]
318+
319+
def __call__(
320+
self,
321+
value: Optional[str],
322+
param: Optional[Parameter] = ...,
323+
ctx: Optional[Context] = ...,
324+
) -> Any:
325+
...
326+
327+
def get_metavar(self, param: Parameter) -> str:
328+
...
329+
330+
def get_missing_message(self, param: Parameter) -> str:
331+
...
332+
333+
def convert(
334+
self,
335+
value: str,
336+
param: Optional[Parameter],
337+
ctx: Optional[Context],
338+
) -> Any:
339+
...
340+
341+
def split_envvar_value(self, rv: str) -> List[str]:
342+
...
343+
344+
def fail(self, message: str, param: Optional[Parameter] = ..., ctx: Optional[Context] = ...) -> None:
345+
...
346+
347+
348+
# This type is here to resolve https://github.com/python/mypy/issues/5275
349+
_ConvertibleType = Union[type, _ParamType, Tuple[type, ...], Callable[[str], Any], Callable[[Optional[str]], Any]]
350+
351+
316352
class Parameter:
317353
param_type_name: str
318354
name: str
319355
opts: List[str]
320356
secondary_opts: List[str]
321-
type: ParamType
357+
type: _ParamType
322358
required: bool
323359
callback: Optional[Callable[[Context, 'Parameter', str], Any]]
324360
nargs: int

third_party/2and3/click/decorators.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from distutils.version import Version
22
from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, Text
33

4-
from click.core import Command, Group, Argument, Option, Parameter, Context
5-
from click.types import _ConvertibleType
4+
from click.core import Command, Group, Argument, Option, Parameter, Context, _ConvertibleType
65

76
_T = TypeVar('_T')
87
_Decorator = Callable[[_T], _T]

third_party/2and3/click/termui.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ from typing import (
1212
TypeVar,
1313
)
1414

15-
from click.types import _ConvertibleType
15+
from click.core import _ConvertibleType
1616
from click._termui_impl import ProgressBar as _ProgressBar
1717

1818

third_party/2and3/click/types.pyi

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
11
from typing import Any, Callable, IO, Iterable, List, Optional, TypeVar, Union, Tuple as _PyTuple, Type
22
import uuid
33

4-
from click.core import Context, Parameter
5-
6-
7-
class ParamType:
8-
name: str
9-
is_composite: bool
10-
envvar_list_splitter: Optional[str]
11-
12-
def __call__(
13-
self,
14-
value: Optional[str],
15-
param: Optional[Parameter] = ...,
16-
ctx: Optional[Context] = ...,
17-
) -> Any:
18-
...
19-
20-
def get_metavar(self, param: Parameter) -> str:
21-
...
22-
23-
def get_missing_message(self, param: Parameter) -> str:
24-
...
25-
26-
def convert(
27-
self,
28-
value: str,
29-
param: Optional[Parameter],
30-
ctx: Optional[Context],
31-
) -> Any:
32-
...
33-
34-
def split_envvar_value(self, rv: str) -> List[str]:
35-
...
36-
37-
def fail(self, message: str, param: Optional[Parameter] = ..., ctx: Optional[Context] = ...) -> None:
38-
...
39-
4+
from click.core import Context, Parameter, _ParamType as ParamType, _ConvertibleType
405

416
class BoolParamType(ParamType):
427
def __call__(
@@ -270,8 +235,6 @@ class UUIDParameterType(ParamType):
270235
...
271236

272237

273-
_ConvertibleType = Union[type, ParamType, _PyTuple[type, ...], Callable[[str], Any], Callable[[Optional[str]], Any]]
274-
275238
def convert_type(ty: Optional[_ConvertibleType], default: Optional[Any] = ...) -> ParamType:
276239
...
277240

0 commit comments

Comments
 (0)