6565 int ,
6666]
6767
68+ _FileLike : "typing.TypeAlias" = Union [str , os .PathLike [str ], typing .IO [bytes ]]
69+
6870_wrapper_file_obj_type : "typing.TypeAlias" = Union [
6971 _tensorizer_file_obj_type ,
70- Callable [[torch . types . FileLike ], _tensorizer_file_obj_type ],
72+ Callable [[_FileLike ], _tensorizer_file_obj_type ],
7173]
7274
7375_save_func_type : "typing.TypeAlias" = Callable [
@@ -397,7 +399,7 @@ def _pickle_attr(name):
397399_ORIG_TORCH_LOAD : Final [callable ] = torch .load
398400
399401
400- def _infer_tensor_ext_name (f : torch . types . FileLike ):
402+ def _infer_tensor_ext_name (f : _FileLike ):
401403 if isinstance (f , io .BytesIO ):
402404 logger .warning (
403405 "Cannot infer .tensors location from io.BytesIO;"
@@ -418,7 +420,7 @@ def _infer_tensor_ext_name(f: torch.types.FileLike):
418420
419421@contextlib .contextmanager
420422def _contextual_torch_filename (
421- f : torch . types . FileLike ,
423+ f : _FileLike ,
422424 filename_ctx_var : ContextVar [Optional [_wrapper_file_obj_type ]],
423425):
424426 if filename_ctx_var .get () is None :
@@ -462,7 +464,7 @@ def _contextual_torch_filename(
462464@functools .wraps (_ORIG_TORCH_SAVE )
463465def _save_wrapper (
464466 obj : object ,
465- f : torch . types . FileLike ,
467+ f : _FileLike ,
466468 pickle_module : Any = pickle ,
467469 * args ,
468470 ** kwargs ,
@@ -489,7 +491,7 @@ def _save_wrapper(
489491
490492@functools .wraps (_ORIG_TORCH_LOAD )
491493def _load_wrapper (
492- f : torch . types . FileLike ,
494+ f : _FileLike ,
493495 map_location : torch .serialization .MAP_LOCATION = None ,
494496 pickle_module : Any = _LOAD_WRAPPER_DEFAULT_MODULE ,
495497 * args ,
0 commit comments