Skip to content

Commit

Permalink
Fix mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhdu committed May 23, 2023
1 parent 93518cf commit bcfc139
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 18 deletions.
1 change: 0 additions & 1 deletion fsspec/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class NotThisMethod(Exception):
"""Exception raised if a method is not valid for the current scenario."""


LONG_VERSION_PY = {}
HANDLERS = {}


Expand Down
6 changes: 4 additions & 2 deletions fsspec/asyn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import TYPE_CHECKING
import asyncio
import asyncio.events
import functools
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion fsspec/config.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
9 changes: 6 additions & 3 deletions fsspec/gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import ClassVar, Sequence
import ast
import contextlib
import logging
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion fsspec/implementations/cached.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import ClassVar, Union, Tuple
import contextlib
import hashlib
import inspect
Expand Down Expand Up @@ -39,7 +40,7 @@ class CachingFileSystem(AbstractFileSystem):
allowed, for testing
"""

protocol = ("blockcache", "cached")
protocol: ClassVar[Union[str, Tuple[str, ...]]] = ("blockcache", "cached")

def __init__(
self,
Expand Down
4 changes: 3 additions & 1 deletion fsspec/implementations/memory.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = "/"
Expand Down
10 changes: 5 additions & 5 deletions fsspec/implementations/reference.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import TYPE_CHECKING
import base64
import collections
import io
Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)
Expand All @@ -938,7 +939,6 @@ def _process_templates(self, tmp):
self.templates[k] = v

def _process_gen(self, gens):

out = {}
for gen in gens:
dimension = {
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fsspec/registry.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Dict, Type
import importlib
import types
import warnings

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

# internal, mutable
_registry = {}
_registry: Dict[str, Type] = {}

# external, immutable
registry = types.MappingProxyType(_registry)
Expand Down
3 changes: 2 additions & 1 deletion fsspec/spec.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Union, Tuple, ClassVar
import io
import logging
import os
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fsspec/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Dict
import logging
import math
import os
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit bcfc139

Please sign in to comment.