diff --git a/fsspec/_version.py b/fsspec/_version.py index 1625f611e..48b1aab50 100644 --- a/fsspec/_version.py +++ b/fsspec/_version.py @@ -51,7 +51,6 @@ class NotThisMethod(Exception): """Exception raised if a method is not valid for the current scenario.""" -LONG_VERSION_PY = {} HANDLERS = {} diff --git a/fsspec/asyn.py b/fsspec/asyn.py index d4e309790..fae1c51a6 100644 --- a/fsspec/asyn.py +++ b/fsspec/asyn.py @@ -1,3 +1,4 @@ +from typing import TYPE_CHECKING import asyncio import asyncio.events import functools @@ -151,8 +152,9 @@ def get_loop(): try: import resource except ImportError: - resource = None - ResourceError = OSError + if not TYPE_CHECKING: + resource = None + ResourceError = OSError else: ResourceEror = resource.error diff --git a/fsspec/config.py b/fsspec/config.py index 685582938..1344d0b01 100644 --- a/fsspec/config.py +++ b/fsspec/config.py @@ -1,9 +1,10 @@ +from typing import Any, Dict import configparser import json import os import warnings -conf = {} +conf: Dict[str, Dict[str, Any]] = {} default_conf_dir = os.path.join(os.path.expanduser("~"), ".config/fsspec") conf_dir = os.environ.get("FSSPEC_CONFIG_DIR", default_conf_dir) diff --git a/fsspec/gui.py b/fsspec/gui.py index 78eae1cf9..e5f42430f 100644 --- a/fsspec/gui.py +++ b/fsspec/gui.py @@ -1,3 +1,4 @@ +from typing import ClassVar, Sequence import ast import contextlib import logging @@ -25,9 +26,11 @@ class SigSlot(object): By default, all signals emit a DEBUG logging statement. """ - signals = [] # names of signals that this class may emit - # each of which must be set by _register for any new instance - slots = [] # names of actions that this class may respond to + # names of signals that this class may emit each of which must be + # set by _register for any new instance + signals: ClassVar[Sequence[str]] = [] + # names of actions that this class may respond to + slots: ClassVar[Sequence[str]] = [] # each of which must be a method name diff --git a/fsspec/implementations/cached.py b/fsspec/implementations/cached.py index 31fb3fffe..e23bd362c 100644 --- a/fsspec/implementations/cached.py +++ b/fsspec/implementations/cached.py @@ -1,3 +1,4 @@ +from typing import ClassVar, Union, Tuple import contextlib import hashlib import inspect @@ -39,7 +40,7 @@ class CachingFileSystem(AbstractFileSystem): allowed, for testing """ - protocol = ("blockcache", "cached") + protocol: ClassVar[Union[str, Tuple[str, ...]]] = ("blockcache", "cached") def __init__( self, diff --git a/fsspec/implementations/memory.py b/fsspec/implementations/memory.py index 120f5aadd..dc204971a 100644 --- a/fsspec/implementations/memory.py +++ b/fsspec/implementations/memory.py @@ -1,5 +1,7 @@ from __future__ import absolute_import, division, print_function +from typing import Any, ClassVar, Dict + import logging from datetime import datetime from errno import ENOTEMPTY @@ -17,7 +19,7 @@ class MemoryFileSystem(AbstractFileSystem): in memory filesystem. """ - store = {} # global, do not overwrite! + store: ClassVar[Dict[str, Any]] = {} # global, do not overwrite! pseudo_dirs = [""] # global, do not overwrite! protocol = "memory" root_marker = "/" diff --git a/fsspec/implementations/reference.py b/fsspec/implementations/reference.py index a17143ac1..da1c24c1b 100644 --- a/fsspec/implementations/reference.py +++ b/fsspec/implementations/reference.py @@ -1,3 +1,4 @@ +from typing import TYPE_CHECKING import base64 import collections import io @@ -12,7 +13,8 @@ try: import ujson as json except ImportError: - import json + if not TYPE_CHECKING: + import json from ..asyn import AsyncFileSystem from ..callbacks import _DEFAULT_CALLBACK @@ -802,11 +804,11 @@ def cat(self, path, recursive=False, on_error="raise", **kwargs): urls.append(u) starts.append(s) ends.append(e) - except FileNotFoundError as e: + except FileNotFoundError as err: if on_error == "raise": raise if on_error != "omit": - out[p] = e + out[p] = err # process references into form for merging urls2 = [] @@ -923,7 +925,6 @@ def _render_jinja(u): self.references.update(self._process_gen(references.get("gen", []))) def _process_templates(self, tmp): - self.templates = {} if self.template_overrides is not None: tmp.update(self.template_overrides) @@ -938,7 +939,6 @@ def _process_templates(self, tmp): self.templates[k] = v def _process_gen(self, gens): - out = {} for gen in gens: dimension = { diff --git a/fsspec/implementations/tar.py b/fsspec/implementations/tar.py index 772ebd4d6..62bb58f84 100644 --- a/fsspec/implementations/tar.py +++ b/fsspec/implementations/tar.py @@ -81,7 +81,7 @@ def __init__( self._fo_ref = fo self.fo = fo # the whole instance is a context - self.tar: tarfile.TarFile = tarfile.TarFile(fileobj=self.fo) + self.tar = tarfile.TarFile(fileobj=self.fo) self.dir_cache = None self.index_store = index_store diff --git a/fsspec/registry.py b/fsspec/registry.py index c6ef1b08f..957e0d6f8 100644 --- a/fsspec/registry.py +++ b/fsspec/registry.py @@ -1,3 +1,4 @@ +from typing import Dict, Type import importlib import types import warnings @@ -5,7 +6,7 @@ __all__ = ["registry", "get_filesystem_class", "default"] # internal, mutable -_registry = {} +_registry: Dict[str, Type] = {} # external, immutable registry = types.MappingProxyType(_registry) diff --git a/fsspec/spec.py b/fsspec/spec.py index 493faf4ee..fe3811322 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -1,3 +1,4 @@ +from typing import Union, Tuple, ClassVar import io import logging import os @@ -101,7 +102,7 @@ class AbstractFileSystem(metaclass=_Cached): _cached = False blocksize = 2**22 sep = "/" - protocol = "abstract" + protocol: ClassVar[Union[str, Tuple[str, ...]]] = "abstract" _latest = None async_impl = False mirror_sync_methods = False diff --git a/fsspec/utils.py b/fsspec/utils.py index 51f8cc8d1..a21a9d2eb 100644 --- a/fsspec/utils.py +++ b/fsspec/utils.py @@ -1,3 +1,4 @@ +from typing import Dict import logging import math import os @@ -110,7 +111,7 @@ def update_storage_options(options, inherited=None): # Compression extensions registered via fsspec.compression.register_compression -compressions = {} +compressions: Dict[str, str] = {} def infer_compression(filename):