Skip to content

Commit 200a7bc

Browse files
committed
Fix mypy errors
1 parent 9ecf166 commit 200a7bc

File tree

11 files changed

+35
-22
lines changed

11 files changed

+35
-22
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

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import threading
1010
from contextlib import contextmanager
1111
from glob import has_magic
12-
from typing import Iterable
12+
from typing import TYPE_CHECKING, Iterable
1313

1414
from .callbacks import _DEFAULT_CALLBACK
1515
from .exceptions import FSTimeoutError
@@ -154,13 +154,18 @@ def get_loop():
154154
return loop[0]
155155

156156

157-
try:
157+
if TYPE_CHECKING:
158158
import resource
159-
except ImportError:
160-
resource = None
161-
ResourceError = OSError
159+
160+
ResourceError = resource.error
162161
else:
163-
ResourceError = getattr(resource, "error", IOError)
162+
try:
163+
import resource
164+
except ImportError:
165+
resource = None
166+
ResourceError = OSError
167+
else:
168+
ResourceError = getattr(resource, "error", IOError)
164169

165170
_DEFAULT_BATCH_SIZE = 128
166171
_NOFILES_DEFAULT_BATCH_SIZE = 1280

fsspec/config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import json
33
import os
44
import warnings
5+
from typing import Any, Dict
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
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import re
6+
from typing import ClassVar, Sequence
67

78
import panel as pn
89

@@ -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
@@ -7,6 +7,7 @@
77
import tempfile
88
import time
99
from shutil import rmtree
10+
from typing import ClassVar, Tuple, Union
1011

1112
from fsspec import AbstractFileSystem, filesystem
1213
from fsspec.callbacks import _DEFAULT_CALLBACK
@@ -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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime
55
from errno import ENOTEMPTY
66
from io import BytesIO
7+
from typing import Any, ClassVar, Dict
78

89
from fsspec import AbstractFileSystem
910

@@ -17,7 +18,7 @@ class MemoryFileSystem(AbstractFileSystem):
1718
in memory filesystem.
1819
"""
1920

20-
store = {} # global, do not overwrite!
21+
store: ClassVar[Dict[str, Any]] = {} # global, do not overwrite!
2122
pseudo_dirs = [""] # global, do not overwrite!
2223
protocol = "memory"
2324
root_marker = "/"

fsspec/implementations/reference.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import math
77
import os
88
from functools import lru_cache
9+
from typing import TYPE_CHECKING
910

1011
import fsspec.core
1112

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
@@ -803,11 +805,11 @@ def cat(self, path, recursive=False, on_error="raise", **kwargs):
803805
urls.append(u)
804806
starts.append(s)
805807
ends.append(e)
806-
except FileNotFoundError as e:
808+
except FileNotFoundError as err:
807809
if on_error == "raise":
808810
raise
809811
if on_error != "omit":
810-
out[p] = e
812+
out[p] = err
811813

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

926928
def _process_templates(self, tmp):
927-
928929
self.templates = {}
929930
if self.template_overrides is not None:
930931
tmp.update(self.template_overrides)
@@ -939,7 +940,6 @@ def _process_templates(self, tmp):
939940
self.templates[k] = v
940941

941942
def _process_gen(self, gens):
942-
943943
out = {}
944944
for gen in gens:
945945
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 @@
11
import importlib
22
import types
33
import warnings
4+
from typing import Dict, Type
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
@@ -7,6 +7,7 @@
77
from errno import ESPIPE
88
from glob import has_magic
99
from hashlib import sha256
10+
from typing import ClassVar, Tuple, Union
1011

1112
from .callbacks import _DEFAULT_CALLBACK
1213
from .config import apply_config, conf
@@ -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
@@ -8,6 +8,7 @@
88
from functools import partial
99
from hashlib import md5
1010
from importlib.metadata import version
11+
from typing import Dict
1112
from urllib.parse import urlsplit
1213

1314
DEFAULT_BLOCK_SIZE = 5 * 2**20
@@ -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)