Skip to content

Commit ee914c0

Browse files
committed
Replace Type with type when typing
1 parent da7b4de commit ee914c0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/tap/tapify.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import dataclasses
99
import inspect
10-
from typing import Any, Callable, Optional, Sequence, Type, TypeVar, Union
10+
from typing import Any, Callable, Optional, Sequence, TypeVar, Union
1111

1212
from docstring_parser import Docstring, parse
1313
from packaging.version import Version
@@ -35,7 +35,7 @@
3535
InputType = TypeVar("InputType")
3636
OutputType = TypeVar("OutputType")
3737

38-
_ClassOrFunction = Union[Callable[[InputType], OutputType], Type[OutputType]]
38+
_ClassOrFunction = Union[Callable[[InputType], OutputType], type[OutputType]]
3939

4040

4141
@dataclasses.dataclass
@@ -46,7 +46,7 @@ class _ArgData:
4646

4747
name: str
4848

49-
annotation: Type
49+
annotation: type
5050
"The type of values this argument accepts"
5151

5252
is_required: bool
@@ -78,14 +78,14 @@ class _TapData:
7878
"If true, ignore extra arguments and only parse known arguments"
7979

8080

81-
def _is_pydantic_base_model(obj: Union[Type[Any], Any]) -> bool:
81+
def _is_pydantic_base_model(obj: Union[type[Any], Any]) -> bool:
8282
if inspect.isclass(obj): # issubclass requires that obj is a class
8383
return issubclass(obj, BaseModel)
8484
else:
8585
return isinstance(obj, BaseModel)
8686

8787

88-
def _is_pydantic_dataclass(obj: Union[Type[Any], Any]) -> bool:
88+
def _is_pydantic_dataclass(obj: Union[type[Any], Any]) -> bool:
8989
if _IS_PYDANTIC_V1:
9090
# There's no public function in v1. This is a somewhat safe but linear check
9191
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:
124124
description,
125125
)
126126

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:
128128
annotation = field.annotation if annotation is None else annotation
129129
# Prefer the description from param_to_description (from the data model / class docstring) over the
130130
# 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(
227227
return _TapData(args_data, has_kwargs, known_only)
228228

229229

230-
def _is_data_model(obj: Union[Type[Any], Any]) -> bool:
230+
def _is_data_model(obj: Union[type[Any], Any]) -> bool:
231231
return dataclasses.is_dataclass(obj) or _is_pydantic_base_model(obj)
232232

233233

@@ -258,7 +258,7 @@ def _tap_data(class_or_function: _ClassOrFunction, param_to_description: dict[st
258258
return _tap_data_from_class_or_function(class_or_function, func_kwargs, param_to_description)
259259

260260

261-
def _tap_class(args_data: Sequence[_ArgData]) -> Type[Tap]:
261+
def _tap_class(args_data: Sequence[_ArgData]) -> type[Tap]:
262262
"""
263263
Transfers argument data to a :class:`tap.Tap` class. Arguments will be added to the parser on initialization.
264264
"""
@@ -282,7 +282,7 @@ def _configure(self):
282282
return ArgParser
283283

284284

285-
def to_tap_class(class_or_function: _ClassOrFunction) -> Type[Tap]:
285+
def to_tap_class(class_or_function: _ClassOrFunction) -> type[Tap]:
286286
"""Creates a `Tap` class from `class_or_function`. This can be subclassed to add custom argument handling and
287287
instantiated to create a typed argument parser.
288288
@@ -296,7 +296,7 @@ def to_tap_class(class_or_function: _ClassOrFunction) -> Type[Tap]:
296296

297297

298298
def tapify(
299-
class_or_function: Union[Callable[[InputType], OutputType], Type[OutputType]],
299+
class_or_function: Union[Callable[[InputType], OutputType], type[OutputType]],
300300
known_only: bool = False,
301301
command_line_args: Optional[list[str]] = None,
302302
explicit_bool: bool = False,

0 commit comments

Comments
 (0)