Skip to content

Commit bcfc139

Browse files
committed
Fix mypy errors
1 parent 93518cf commit bcfc139

File tree

11 files changed

+29
-18
lines changed

11 files changed

+29
-18
lines changed

fsspec/_version.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class NotThisMethod(Exception):
5151
"""Exception raised if a method is not valid for the current scenario."""
5252

5353

54-
LONG_VERSION_PY = {}
5554
HANDLERS = {}
5655

5756

fsspec/asyn.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import TYPE_CHECKING
12
import asyncio
23
import asyncio.events
34
import functools
@@ -151,8 +152,9 @@ def get_loop():
151152
try:
152153
import resource
153154
except ImportError:
154-
resource = None
155-
ResourceError = OSError
155+
if not TYPE_CHECKING:
156+
resource = None
157+
ResourceError = OSError
156158
else:
157159
ResourceEror = resource.error
158160

fsspec/config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from typing import Any, Dict
12
import configparser
23
import json
34
import os
45
import warnings
56

6-
conf = {}
7+
conf: Dict[str, Dict[str, Any]] = {}
78
default_conf_dir = os.path.join(os.path.expanduser("~"), ".config/fsspec")
89
conf_dir = os.environ.get("FSSPEC_CONFIG_DIR", default_conf_dir)
910

fsspec/gui.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import ClassVar, Sequence
12
import ast
23
import contextlib
34
import logging
@@ -25,9 +26,11 @@ class SigSlot(object):
2526
By default, all signals emit a DEBUG logging statement.
2627
"""
2728

28-
signals = [] # names of signals that this class may emit
29-
# each of which must be set by _register for any new instance
30-
slots = [] # names of actions that this class may respond to
29+
# names of signals that this class may emit each of which must be
30+
# set by _register for any new instance
31+
signals: ClassVar[Sequence[str]] = []
32+
# names of actions that this class may respond to
33+
slots: ClassVar[Sequence[str]] = []
3134

3235
# each of which must be a method name
3336

fsspec/implementations/cached.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import ClassVar, Union, Tuple
12
import contextlib
23
import hashlib
34
import inspect
@@ -39,7 +40,7 @@ class CachingFileSystem(AbstractFileSystem):
3940
allowed, for testing
4041
"""
4142

42-
protocol = ("blockcache", "cached")
43+
protocol: ClassVar[Union[str, Tuple[str, ...]]] = ("blockcache", "cached")
4344

4445
def __init__(
4546
self,

fsspec/implementations/memory.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import absolute_import, division, print_function
22

3+
from typing import Any, ClassVar, Dict
4+
35
import logging
46
from datetime import datetime
57
from errno import ENOTEMPTY
@@ -17,7 +19,7 @@ class MemoryFileSystem(AbstractFileSystem):
1719
in memory filesystem.
1820
"""
1921

20-
store = {} # global, do not overwrite!
22+
store: ClassVar[Dict[str, Any]] = {} # global, do not overwrite!
2123
pseudo_dirs = [""] # global, do not overwrite!
2224
protocol = "memory"
2325
root_marker = "/"

fsspec/implementations/reference.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import TYPE_CHECKING
12
import base64
23
import collections
34
import io
@@ -12,7 +13,8 @@
1213
try:
1314
import ujson as json
1415
except ImportError:
15-
import json
16+
if not TYPE_CHECKING:
17+
import json
1618

1719
from ..asyn import AsyncFileSystem
1820
from ..callbacks import _DEFAULT_CALLBACK
@@ -802,11 +804,11 @@ def cat(self, path, recursive=False, on_error="raise", **kwargs):
802804
urls.append(u)
803805
starts.append(s)
804806
ends.append(e)
805-
except FileNotFoundError as e:
807+
except FileNotFoundError as err:
806808
if on_error == "raise":
807809
raise
808810
if on_error != "omit":
809-
out[p] = e
811+
out[p] = err
810812

811813
# process references into form for merging
812814
urls2 = []
@@ -923,7 +925,6 @@ def _render_jinja(u):
923925
self.references.update(self._process_gen(references.get("gen", [])))
924926

925927
def _process_templates(self, tmp):
926-
927928
self.templates = {}
928929
if self.template_overrides is not None:
929930
tmp.update(self.template_overrides)
@@ -938,7 +939,6 @@ def _process_templates(self, tmp):
938939
self.templates[k] = v
939940

940941
def _process_gen(self, gens):
941-
942942
out = {}
943943
for gen in gens:
944944
dimension = {

fsspec/implementations/tar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181

8282
self._fo_ref = fo
8383
self.fo = fo # the whole instance is a context
84-
self.tar: tarfile.TarFile = tarfile.TarFile(fileobj=self.fo)
84+
self.tar = tarfile.TarFile(fileobj=self.fo)
8585
self.dir_cache = None
8686

8787
self.index_store = index_store

fsspec/registry.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from typing import Dict, Type
12
import importlib
23
import types
34
import warnings
45

56
__all__ = ["registry", "get_filesystem_class", "default"]
67

78
# internal, mutable
8-
_registry = {}
9+
_registry: Dict[str, Type] = {}
910

1011
# external, immutable
1112
registry = types.MappingProxyType(_registry)

fsspec/spec.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Union, Tuple, ClassVar
12
import io
23
import logging
34
import os
@@ -101,7 +102,7 @@ class AbstractFileSystem(metaclass=_Cached):
101102
_cached = False
102103
blocksize = 2**22
103104
sep = "/"
104-
protocol = "abstract"
105+
protocol: ClassVar[Union[str, Tuple[str, ...]]] = "abstract"
105106
_latest = None
106107
async_impl = False
107108
mirror_sync_methods = False

fsspec/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Dict
12
import logging
23
import math
34
import os
@@ -110,7 +111,7 @@ def update_storage_options(options, inherited=None):
110111

111112

112113
# Compression extensions registered via fsspec.compression.register_compression
113-
compressions = {}
114+
compressions: Dict[str, str] = {}
114115

115116

116117
def infer_compression(filename):

0 commit comments

Comments
 (0)