Skip to content

Commit 46b867b

Browse files
tomvdwThe TensorFlow Datasets Authors
authored andcommitted
Update some types to modern Python
PiperOrigin-RevId: 686064548
1 parent a57f75f commit 46b867b

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

tensorflow_datasets/core/logging/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import collections
2121
import functools
2222
import threading
23-
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar
23+
from typing import Any, Callable, TypeVar
2424

2525
from absl import flags
2626
from absl import logging
@@ -34,15 +34,15 @@
3434
_LoggerMethod = Callable[..., None]
3535

3636

37-
_registered_loggers: Optional[List[base_logger.Logger]] = None
37+
_registered_loggers: list[base_logger.Logger] | None = None
3838

39-
_import_operations: List[Tuple[call_metadata.CallMetadata, int, int]] = []
39+
_import_operations: list[tuple[call_metadata.CallMetadata, int, int]] = []
4040
_import_operations_lock = threading.Lock()
4141

4242
_thread_id_to_builder_init_count = collections.Counter()
4343

4444

45-
def _init_registered_loggers() -> List[base_logger.Logger]:
45+
def _init_registered_loggers() -> list[base_logger.Logger]:
4646
"""Initializes the registered loggers if they are not set yet."""
4747
global _registered_loggers
4848
if _registered_loggers is None:
@@ -65,7 +65,7 @@ def _log_import_operation():
6565
_import_operations.clear()
6666

6767

68-
def _get_registered_loggers() -> List[base_logger.Logger]:
68+
def _get_registered_loggers() -> list[base_logger.Logger]:
6969
_log_import_operation()
7070
return _init_registered_loggers()
7171

@@ -188,7 +188,7 @@ class _DsbuilderMethodDecorator(_FunctionDecorator):
188188
IS_PROPERTY: bool = False
189189

190190
@staticmethod
191-
def _get_info(dsbuilder: Any) -> Tuple[str, str, str, str]:
191+
def _get_info(dsbuilder: Any) -> tuple[str, str, str, str]:
192192
"""Gets information about the builder.
193193
194194
Args:

tensorflow_datasets/core/logging/base_logger.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from __future__ import annotations
1919

20-
from typing import Any, Dict, Optional, Union
20+
from typing import Any
2121

2222
from etils import epy
2323

@@ -51,7 +51,7 @@ def tfds_import(
5151
metadata: call_metadata.CallMetadata,
5252
import_time_ms_tensorflow: int,
5353
import_time_ms_dataset_builders: int,
54-
):
54+
) -> None:
5555
"""Callback called when user calls `import tensorflow_datasets`."""
5656
pass
5757

@@ -60,11 +60,11 @@ def builder_init(
6060
*,
6161
metadata: call_metadata.CallMetadata,
6262
name: str,
63-
data_dir: Optional[str],
64-
config: Optional[str],
65-
version: Optional[str],
63+
data_dir: str | None,
64+
config: str | None,
65+
version: str | None,
6666
is_read_only_builder: bool,
67-
):
67+
) -> None:
6868
"""Callback called when user calls `DatasetBuilder(...)`."""
6969
pass
7070

@@ -73,10 +73,10 @@ def builder_info(
7373
*,
7474
metadata: call_metadata.CallMetadata,
7575
name: str,
76-
config_name: Optional[str],
76+
config_name: str | None,
7777
version: str,
7878
data_path: str,
79-
):
79+
) -> None:
8080
"""Callback called when user calls `builder.info()`."""
8181
pass
8282

@@ -85,16 +85,16 @@ def as_dataset(
8585
*,
8686
metadata: call_metadata.CallMetadata,
8787
name: str,
88-
config_name: Optional[str],
88+
config_name: str | None,
8989
version: str,
9090
data_path: str,
91-
split: Optional[type_utils.Tree[splits_lib.SplitArg]],
92-
batch_size: Optional[int],
91+
split: type_utils.Tree[splits_lib.SplitArg] | None,
92+
batch_size: int | None,
9393
shuffle_files: bool,
9494
read_config: read_config_lib.ReadConfig,
9595
as_supervised: bool,
96-
decoders: Optional[TreeDict[decode.partial_decode.DecoderArg]],
97-
):
96+
decoders: TreeDict[decode.partial_decode.DecoderArg] | None,
97+
) -> None:
9898
"""Callback called when user calls `dataset_builder.as_dataset`.
9999
100100
Callback is also triggered by `tfds.load`, which calls `as_dataset`.
@@ -122,13 +122,13 @@ def download_and_prepare(
122122
*,
123123
metadata: call_metadata.CallMetadata,
124124
name: str,
125-
config_name: Optional[str],
125+
config_name: str | None,
126126
version: str,
127127
data_path: str,
128-
download_dir: Optional[str],
129-
download_config: Optional[download_lib.DownloadConfig],
130-
file_format: Union[None, str, file_adapters.FileFormat],
131-
):
128+
download_dir: str | None,
129+
download_config: download_lib.DownloadConfig | None,
130+
file_format: str | file_adapters.FileFormat | None,
131+
) -> None:
132132
"""Callback called when user calls `dataset_builder.download_and_prepare`."""
133133
pass
134134

@@ -141,17 +141,17 @@ def builder(
141141
*,
142142
metadata: call_metadata.CallMetadata,
143143
name: str,
144-
try_gcs: Optional[bool],
145-
):
144+
try_gcs: bool | None,
145+
) -> None:
146146
"""Callback called when user calls `tfds.builder(...)`."""
147147
pass
148148

149149
def dataset_collection(
150150
self,
151151
metadata: call_metadata.CallMetadata,
152152
name: str,
153-
loader_kwargs: Optional[Dict[str, Any]],
154-
):
153+
loader_kwargs: dict[str, Any] | None,
154+
) -> None:
155155
"""Callback called when user calls `tfds.dataset_collection(...)`."""
156156
pass
157157

@@ -160,26 +160,26 @@ def load(
160160
*,
161161
metadata: call_metadata.CallMetadata,
162162
name: str,
163-
split: Optional[type_utils.Tree[splits_lib.SplitArg]],
164-
data_dir: Optional[str],
165-
batch_size: Optional[int],
166-
shuffle_files: Optional[bool],
167-
download: Optional[bool],
168-
as_supervised: Optional[bool],
169-
decoders: Optional[TreeDict[decode.partial_decode.DecoderArg]],
170-
read_config: Optional[read_config_lib.ReadConfig],
171-
with_info: Optional[bool],
172-
try_gcs: Optional[bool],
173-
):
163+
split: type_utils.Tree[splits_lib.SplitArg] | None,
164+
data_dir: str | None,
165+
batch_size: int | None,
166+
shuffle_files: bool | None,
167+
download: bool | None,
168+
as_supervised: bool | None,
169+
decoders: TreeDict[decode.partial_decode.DecoderArg] | None,
170+
read_config: read_config_lib.ReadConfig | None,
171+
with_info: bool | None,
172+
try_gcs: bool | None,
173+
) -> None:
174174
"""Callback called when user calls `tfds.load(...)`."""
175175
pass
176176

177177
def list_builders(
178178
self,
179179
*,
180180
metadata: call_metadata.CallMetadata,
181-
with_community_datasets: Optional[bool],
182-
):
181+
with_community_datasets: bool | None,
182+
) -> None:
183183
"""Callback called when user calls `tfds.list_builders(...)`."""
184184
pass
185185

@@ -192,12 +192,12 @@ def data_source(
192192
*,
193193
metadata: call_metadata.CallMetadata,
194194
name: str,
195-
split: Optional[type_utils.Tree[splits_lib.SplitArg]],
196-
data_dir: Optional[str],
197-
download: Optional[bool],
198-
decoders: Optional[TreeDict[decode.partial_decode.DecoderArg]],
199-
try_gcs: Optional[bool],
200-
):
195+
split: type_utils.Tree[splits_lib.SplitArg] | None,
196+
data_dir: str | None,
197+
download: bool | None,
198+
decoders: TreeDict[decode.partial_decode.DecoderArg] | None,
199+
try_gcs: bool | None,
200+
) -> None:
201201
"""Callback called when user calls `tfds.data_source(...)`."""
202202
pass
203203

@@ -206,11 +206,11 @@ def as_data_source(
206206
*,
207207
metadata: call_metadata.CallMetadata,
208208
name: str,
209-
config_name: Optional[str],
209+
config_name: str | None,
210210
version: str,
211211
data_path: str,
212-
split: Optional[type_utils.Tree[splits_lib.SplitArg]],
213-
decoders: Optional[TreeDict[decode.partial_decode.DecoderArg]],
214-
):
212+
split: type_utils.Tree[splits_lib.SplitArg] | None,
213+
decoders: TreeDict[decode.partial_decode.DecoderArg] | None,
214+
) -> None:
215215
"""Callback called when user calls `dataset_builder.as_data_source(...)`."""
216216
pass

0 commit comments

Comments
 (0)