7
7
8
8
import dataclasses
9
9
import inspect
10
- from typing import Any , Callable , Optional , Sequence , Type , TypeVar , Union
10
+ from typing import Any , Callable , Optional , Sequence , TypeVar , Union
11
11
12
12
from docstring_parser import Docstring , parse
13
13
from packaging .version import Version
35
35
InputType = TypeVar ("InputType" )
36
36
OutputType = TypeVar ("OutputType" )
37
37
38
- _ClassOrFunction = Union [Callable [[InputType ], OutputType ], Type [OutputType ]]
38
+ _ClassOrFunction = Union [Callable [[InputType ], OutputType ], type [OutputType ]]
39
39
40
40
41
41
@dataclasses .dataclass
@@ -46,7 +46,7 @@ class _ArgData:
46
46
47
47
name : str
48
48
49
- annotation : Type
49
+ annotation : type
50
50
"The type of values this argument accepts"
51
51
52
52
is_required : bool
@@ -78,14 +78,14 @@ class _TapData:
78
78
"If true, ignore extra arguments and only parse known arguments"
79
79
80
80
81
- def _is_pydantic_base_model (obj : Union [Type [Any ], Any ]) -> bool :
81
+ def _is_pydantic_base_model (obj : Union [type [Any ], Any ]) -> bool :
82
82
if inspect .isclass (obj ): # issubclass requires that obj is a class
83
83
return issubclass (obj , BaseModel )
84
84
else :
85
85
return isinstance (obj , BaseModel )
86
86
87
87
88
- def _is_pydantic_dataclass (obj : Union [Type [Any ], Any ]) -> bool :
88
+ def _is_pydantic_dataclass (obj : Union [type [Any ], Any ]) -> bool :
89
89
if _IS_PYDANTIC_V1 :
90
90
# There's no public function in v1. This is a somewhat safe but linear check
91
91
return dataclasses .is_dataclass (obj ) and any (key .startswith ("__pydantic" ) for key in obj .__dict__ )
@@ -124,7 +124,7 @@ def is_required(field: dataclasses.Field) -> bool:
124
124
description ,
125
125
)
126
126
127
- def arg_data_from_pydantic (name : str , field : _PydanticField , annotation : Optional [Type ] = None ) -> _ArgData :
127
+ def arg_data_from_pydantic (name : str , field : _PydanticField , annotation : Optional [type ] = None ) -> _ArgData :
128
128
annotation = field .annotation if annotation is None else annotation
129
129
# Prefer the description from param_to_description (from the data model / class docstring) over the
130
130
# field.description b/c a docstring can be modified on the fly w/o causing real issues
@@ -227,7 +227,7 @@ def _tap_data_from_class_or_function(
227
227
return _TapData (args_data , has_kwargs , known_only )
228
228
229
229
230
- def _is_data_model (obj : Union [Type [Any ], Any ]) -> bool :
230
+ def _is_data_model (obj : Union [type [Any ], Any ]) -> bool :
231
231
return dataclasses .is_dataclass (obj ) or _is_pydantic_base_model (obj )
232
232
233
233
@@ -258,7 +258,7 @@ def _tap_data(class_or_function: _ClassOrFunction, param_to_description: dict[st
258
258
return _tap_data_from_class_or_function (class_or_function , func_kwargs , param_to_description )
259
259
260
260
261
- def _tap_class (args_data : Sequence [_ArgData ]) -> Type [Tap ]:
261
+ def _tap_class (args_data : Sequence [_ArgData ]) -> type [Tap ]:
262
262
"""
263
263
Transfers argument data to a :class:`tap.Tap` class. Arguments will be added to the parser on initialization.
264
264
"""
@@ -282,7 +282,7 @@ def _configure(self):
282
282
return ArgParser
283
283
284
284
285
- def to_tap_class (class_or_function : _ClassOrFunction ) -> Type [Tap ]:
285
+ def to_tap_class (class_or_function : _ClassOrFunction ) -> type [Tap ]:
286
286
"""Creates a `Tap` class from `class_or_function`. This can be subclassed to add custom argument handling and
287
287
instantiated to create a typed argument parser.
288
288
@@ -296,7 +296,7 @@ def to_tap_class(class_or_function: _ClassOrFunction) -> Type[Tap]:
296
296
297
297
298
298
def tapify (
299
- class_or_function : Union [Callable [[InputType ], OutputType ], Type [OutputType ]],
299
+ class_or_function : Union [Callable [[InputType ], OutputType ], type [OutputType ]],
300
300
known_only : bool = False ,
301
301
command_line_args : Optional [list [str ]] = None ,
302
302
explicit_bool : bool = False ,
0 commit comments