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

View file

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

View file

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