5656import pickle
5757import threading
5858import time
59- from typing import Awaitable , Optional , Protocol , Sequence , Type , TypeVar
59+ from typing import Awaitable , Protocol , Sequence , TypeVar
6060
6161from absl import logging
6262from etils import epath
@@ -101,7 +101,7 @@ def __call__(
101101 path : epath .Path ,
102102 parents : bool = False ,
103103 exist_ok : bool = False ,
104- mode : Optional [ int ] = None ,
104+ mode : int | None = None ,
105105 ** kwargs ,
106106 ) -> Awaitable [None ]:
107107 """Creates the directory at path."""
@@ -112,10 +112,10 @@ async def _create_tmp_directory(
112112 async_makedir_func : AsyncMakeDirFunc ,
113113 tmp_dir : epath .Path ,
114114 * ,
115- path_permission_mode : Optional [ int ] = None ,
116- checkpoint_metadata_store : Optional [
117- checkpoint_metadata .MetadataStore
118- ] = None ,
115+ path_permission_mode : int | None = None ,
116+ checkpoint_metadata_store : (
117+ checkpoint_metadata .MetadataStore | None
118+ ) = None ,
119119 ** kwargs ,
120120) -> epath .Path :
121121 """Creates a non-deterministic tmp directory for saving for given `final_dir`.
@@ -181,7 +181,7 @@ def _get_tmp_directory(final_path: epath.Path) -> epath.Path:
181181 )
182182
183183
184- def _get_tmp_directory_pattern (final_path_name : Optional [ str ] = None ) -> str :
184+ def _get_tmp_directory_pattern (final_path_name : str | None = None ) -> str :
185185 suffix = r'\.orbax-checkpoint-tmp'
186186 if final_path_name is None :
187187 return '(.+)' + suffix
@@ -197,10 +197,10 @@ def __init__(
197197 temporary_path : epath .Path ,
198198 final_path : epath .Path ,
199199 * ,
200- checkpoint_metadata_store : Optional [
201- checkpoint_metadata .MetadataStore
202- ] = None ,
203- file_options : Optional [ options_lib .FileOptions ] = None ,
200+ checkpoint_metadata_store : (
201+ checkpoint_metadata .MetadataStore | None
202+ ) = None ,
203+ file_options : options_lib .FileOptions | None = None ,
204204 ):
205205 self ._tmp_path = temporary_path
206206 self ._final_path = final_path
@@ -269,7 +269,7 @@ def to_bytes(self) -> bytes:
269269
270270 @classmethod
271271 def from_bytes (
272- cls : Type ['ReadOnlyTemporaryPath' ],
272+ cls : type ['ReadOnlyTemporaryPath' ],
273273 data : bytes ,
274274 ) -> ReadOnlyTemporaryPath :
275275 """Deserializes the object from bytes.
@@ -291,10 +291,10 @@ def from_final(
291291 cls ,
292292 final_path : epath .Path ,
293293 * ,
294- checkpoint_metadata_store : Optional [
295- checkpoint_metadata .MetadataStore
296- ] = None ,
297- file_options : Optional [ options_lib .FileOptions ] = None ,
294+ checkpoint_metadata_store : (
295+ checkpoint_metadata .MetadataStore | None
296+ ) = None ,
297+ file_options : options_lib .FileOptions | None = None ,
298298 ) -> ReadOnlyTemporaryPath :
299299 """Not implemented for ReadOnlyTemporaryPath."""
300300 raise NotImplementedError (
@@ -324,10 +324,10 @@ def from_final(
324324 cls ,
325325 final_path : epath .Path ,
326326 * ,
327- checkpoint_metadata_store : Optional [
328- checkpoint_metadata .MetadataStore
329- ] = None ,
330- file_options : Optional [ options_lib .FileOptions ] = None ,
327+ checkpoint_metadata_store : (
328+ checkpoint_metadata .MetadataStore | None
329+ ) = None ,
330+ file_options : options_lib .FileOptions | None = None ,
331331 ) -> AtomicRenameTemporaryPath :
332332 return cls (
333333 _get_tmp_directory (final_path ),
@@ -399,10 +399,10 @@ def from_final(
399399 cls ,
400400 final_path : epath .Path ,
401401 * ,
402- checkpoint_metadata_store : Optional [
403- checkpoint_metadata .MetadataStore
404- ] = None ,
405- file_options : Optional [ options_lib .FileOptions ] = None ,
402+ checkpoint_metadata_store : (
403+ checkpoint_metadata .MetadataStore | None
404+ ) = None ,
405+ file_options : options_lib .FileOptions | None = None ,
406406 ) -> CommitFileTemporaryPath :
407407 return cls (
408408 final_path ,
@@ -465,9 +465,7 @@ def finalize(
465465async def create_all (
466466 paths : Sequence [atomicity_types .TemporaryPath ],
467467 * ,
468- multiprocessing_options : Optional [
469- options_lib .MultiprocessingOptions
470- ] = None ,
468+ multiprocessing_options : options_lib .MultiprocessingOptions | None = None ,
471469):
472470 """Creates all temporary paths in parallel."""
473471 start = time .time ()
@@ -511,9 +509,7 @@ def create_all_async(
511509 paths : Sequence [atomicity_types .TemporaryPath ],
512510 completion_signals : Sequence [synchronization .HandlerAwaitableSignal ],
513511 * ,
514- multiprocessing_options : Optional [
515- options_lib .MultiprocessingOptions
516- ] = None ,
512+ multiprocessing_options : options_lib .MultiprocessingOptions | None = None ,
517513 subdirectories : Sequence [str ] | None = None ,
518514) -> future .Future :
519515 """Creates all temporary paths in parallel asynchronously.
0 commit comments