diff --git a/mmengine/utils/__init__.py b/mmengine/utils/__init__.py index b830b224451ac0d3926ff78e8c96806c7796bc09..e709a4ef62efe2c91d77a7bf3eed9098ba21672a 100644 --- a/mmengine/utils/__init__.py +++ b/mmengine/utils/__init__.py @@ -1,5 +1,4 @@ # Copyright (c) OpenMMLab. All rights reserved. -# type: ignore from .fileio import (FileClient, dict_from_file, dump, list_from_file, load, register_handler) from .misc import (check_prerequisites, concat_list, deprecated_api_warning, diff --git a/mmengine/utils/fileio/__init__.py b/mmengine/utils/fileio/__init__.py index 77c35a1bf02ca4b79e103689cf9bda800cacaa50..2051b85f7e59bff7bdbaa131849ce8cd31f059a4 100644 --- a/mmengine/utils/fileio/__init__.py +++ b/mmengine/utils/fileio/__init__.py @@ -1,5 +1,4 @@ # Copyright (c) OpenMMLab. All rights reserved. -# type: ignore from .file_client import BaseStorageBackend, FileClient from .handlers import BaseFileHandler, JsonHandler, PickleHandler, YamlHandler from .io import dump, load, register_handler diff --git a/mmengine/utils/fileio/file_client.py b/mmengine/utils/fileio/file_client.py index af2e5f09baed065fedfadf3d92dc4a239aa8200e..afc19bb7406619126935bdabbcbcc5d18b6a5fa3 100644 --- a/mmengine/utils/fileio/file_client.py +++ b/mmengine/utils/fileio/file_client.py @@ -1,5 +1,4 @@ # Copyright (c) OpenMMLab. All rights reserved. -# type: ignore import inspect import os import os.path as osp @@ -9,7 +8,7 @@ import warnings from abc import ABCMeta, abstractmethod from contextlib import contextmanager from pathlib import Path -from typing import Iterable, Iterator, Optional, Tuple, Union +from typing import Any, Generator, Iterator, Optional, Tuple, Union from urllib.request import urlopen import mmengine @@ -298,7 +297,10 @@ class PetrelBackend(BaseStorageBackend): return '/'.join(formatted_paths) @contextmanager - def get_local_path(self, filepath: Union[str, Path]) -> Iterable[str]: + def get_local_path( + self, + filepath: Union[str, + Path]) -> Generator[Union[str, Path], None, None]: """Download a file from ``filepath`` and return a temporary path. ``get_local_path`` is decorated by :meth:`contxtlib.contextmanager`. It @@ -632,7 +634,9 @@ class HardDiskBackend(BaseStorageBackend): @contextmanager def get_local_path( - self, filepath: Union[str, Path]) -> Iterable[Union[str, Path]]: + self, + filepath: Union[str, + Path]) -> Generator[Union[str, Path], None, None]: """Only for unified API and do nothing.""" yield filepath @@ -701,7 +705,8 @@ class HTTPBackend(BaseStorageBackend): return value_buf.decode(encoding) @contextmanager - def get_local_path(self, filepath: str) -> Iterable[str]: + def get_local_path( + self, filepath: str) -> Generator[Union[str, Path], None, None]: """Download a file from ``filepath``. ``get_local_path`` is decorated by :meth:`contxtlib.contextmanager`. It @@ -775,15 +780,17 @@ class FileClient: # backend appears in the collection, the singleton pattern is disabled for # that backend, because if the singleton pattern is used, then the object # returned will be the backend before overwriting - _overridden_backends = set() - _prefix_to_backends = { + _overridden_backends: set = set() + _prefix_to_backends: dict = { 's3': PetrelBackend, 'http': HTTPBackend, 'https': HTTPBackend, } - _overridden_prefixes = set() + _overridden_prefixes: set = set() - _instances = {} + _instances: dict = {} + + client: Any def __new__(cls, backend=None, prefix=None, **kwargs): if backend is None and prefix is None: @@ -1093,7 +1100,10 @@ class FileClient: return self.client.join_path(filepath, *filepaths) @contextmanager - def get_local_path(self, filepath: Union[str, Path]) -> Iterable[str]: + def get_local_path( + self, + filepath: Union[str, + Path]) -> Generator[Union[str, Path], None, None]: """Download data from ``filepath`` and write the data to local path. ``get_local_path`` is decorated by :meth:`contxtlib.contextmanager`. It diff --git a/mmengine/utils/fileio/io.py b/mmengine/utils/fileio/io.py index e2226efd07139d8601b82dd97eed2cac8ade08bf..fbfa93d3731821c71d6651fb11c0ab6d4ab1c35f 100644 --- a/mmengine/utils/fileio/io.py +++ b/mmengine/utils/fileio/io.py @@ -1,5 +1,4 @@ # Copyright (c) OpenMMLab. All rights reserved. -# type: ignore from io import BytesIO, StringIO from pathlib import Path diff --git a/mmengine/utils/fileio/parse.py b/mmengine/utils/fileio/parse.py index fe424594a684e7bfe66ef7881b72b01b94ec876d..582221a3dd0480d5769440e9982bef6a2adff4ca 100644 --- a/mmengine/utils/fileio/parse.py +++ b/mmengine/utils/fileio/parse.py @@ -1,5 +1,4 @@ # Copyright (c) OpenMMLab. All rights reserved. -# type: ignore from io import StringIO from .file_client import FileClient