Add initial static type checking

This commit is contained in:
Joakim Soderlund 2017-08-02 01:49:26 +02:00
parent c41e7be45d
commit cea1fed78f
3 changed files with 13 additions and 12 deletions

View file

@ -27,12 +27,13 @@ import gc
import json
from copy import deepcopy
from io import BytesIO
from typing import FrozenSet
from zipfile import ZipFile, BadZipFile
import requests
from fimfarchive.exceptions import InvalidStoryError, StorySourceError
from fimfarchive.flavors import StorySource, DataFormat, MetaPurity
from fimfarchive.flavors import Flavor, StorySource, DataFormat, MetaPurity
from fimfarchive.stories import Story
@ -43,6 +44,7 @@ __all__ = (
)
FlavorSet = FrozenSet[Flavor]
StreamReader = codecs.getreader('utf-8')
@ -53,7 +55,7 @@ class Fetcher:
prefetch_meta = False
prefetch_data = False
flavors = frozenset()
flavors = frozenset() # type: FlavorSet
def __enter__(self):
"""

View file

@ -25,7 +25,7 @@ Various utilities.
import json
import os
import shutil
from collections import UserDict
from typing import Dict, Any
__all__ = (
@ -52,7 +52,7 @@ class Empty(metaclass=EmptyMeta):
return False
class PersistedDict(UserDict):
class PersistedDict(Dict[str, Any]):
"""
Dictionary for simple persistance.
"""
@ -75,22 +75,19 @@ class PersistedDict(UserDict):
"""
Loads data from file as JSON.
"""
self.clear()
self.update(self.default)
if os.path.exists(self.path):
with open(self.path, 'rt') as fobj:
self.data = json.load(fobj)
else:
self.data = dict()
for k, v in self.default.items():
if k not in self.data:
self.data[k] = v
self.update(json.load(fobj))
def save(self):
"""
Saves data to file as JSON.
"""
content = json.dumps(
self.data,
self,
indent=4,
ensure_ascii=False,
sort_keys=True,

View file

@ -10,10 +10,12 @@ python =
commands =
py.test
flake8 fimfarchive tests
mypy --ignore-missing-imports fimfarchive
deps =
-rrequirements.txt
pytest
flake8
mypy
[pytest]
addopts =