Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
fix various failing strict type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Oct 9, 2019
1 parent 0d9b772 commit f37dd1f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion collectfast/management/commands/collectstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, *args, **kwargs):

@staticmethod
def _load_strategy():
# type: () -> Type[Strategy]
# type: () -> Type[Strategy[Storage]]
strategy_str = getattr(django_settings, "COLLECTFAST_STRATEGY", None)
if strategy_str is not None:
return load_strategy(strategy_str)
Expand Down Expand Up @@ -78,6 +78,7 @@ def collect(self):
return ret

def handle(self, *args, **options):
# type: (Any, Any) -> str
"""Override handle to suppress summary output."""
super().handle(**options)
return "{} static file{} copied.".format(
Expand Down
2 changes: 1 addition & 1 deletion collectfast/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_gzipped_local_file_hash(self, uncompressed_file_hash, path, contents):
return str(file_hash)


def load_strategy(klass: Union[str, type, object]) -> Type[Strategy]:
def load_strategy(klass: Union[str, type, object]) -> Type[Strategy[Storage]]:
if isinstance(klass, str):
klass = locate(klass)
if not isinstance(klass, type) or not issubclass(klass, Strategy):
Expand Down
4 changes: 3 additions & 1 deletion collectfast/tests/strategies/test_caching_hash_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
hash_characters = string.ascii_letters + string.digits


class Strategy(CachingHashStrategy):
class Strategy(CachingHashStrategy[FileSystemStorage]):
def __init__(self):
# type: () -> None
super().__init__(FileSystemStorage())

def get_remote_file_hash(self, prefixed_path):
# type: (str) -> None
pass


Expand Down
3 changes: 2 additions & 1 deletion collectfast/tests/strategies/test_hash_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
from collectfast.tests.utils import test


class Strategy(HashStrategy):
class Strategy(HashStrategy[FileSystemStorage]):
def __init__(self):
# type: () -> None
super().__init__(FileSystemStorage())

def get_remote_file_hash(self, prefixed_path):
# type: (str) -> None
pass


Expand Down
14 changes: 10 additions & 4 deletions collectfast/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import uuid
from typing import Any
from typing import Callable
from typing import cast
from typing import Type
from typing import TypeVar

from django.conf import settings as django_settings
Expand All @@ -14,11 +16,12 @@

from collectfast import settings

F = TypeVar("F", bound=Callable)
F = TypeVar("F", bound=Callable[..., Any])
static_dir = pathlib.Path(django_settings.STATICFILES_DIRS[0]) # type: Final


def test(func):
# type: (F) -> Type[unittest.TestCase]
"""
Creates a class that inherits from `unittest.TestCase` with the decorated
function as a method. Create tests like this:
Expand All @@ -34,8 +37,9 @@ def test(func):


def test_many(**mutations):
# type: (Callable[[F], F]) -> Callable[[F], F]
# type: (Callable[[F], F]) -> Callable[[F], Type[unittest.TestCase]]
def test(func):
# type: (F) -> Type[unittest.TestCase]
"""
Creates a class that inherits from `unittest.TestCase` with the decorated
function as a method. Create tests like this:
Expand Down Expand Up @@ -77,6 +81,7 @@ def clean_static_dir():
def override_setting(name, value):
# type: (str, Any) -> Callable[[F], F]
def decorator(fn):
# type: (F) -> F
@functools.wraps(fn)
def wrapper(*args, **kwargs):
original = getattr(settings, name)
Expand All @@ -86,14 +91,15 @@ def wrapper(*args, **kwargs):
finally:
setattr(settings, name, original)

return wrapper
return cast(F, wrapper)

return decorator


def override_storage_attr(name, value):
# type: (str, Any) -> Callable[[F], F]
def decorator(fn):
# type: (F) -> F
@functools.wraps(fn)
def wrapper(*args, **kwargs):
storage = import_string(django_settings.STATICFILES_STORAGE)
Expand All @@ -104,6 +110,6 @@ def wrapper(*args, **kwargs):
finally:
setattr(storage, name, original)

return wrapper
return cast(F, wrapper)

return decorator
2 changes: 1 addition & 1 deletion lint-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ flake8-bugbear
black
sorti
mypy>=0.730
git+https://github.com/typeddjango/django-stubs.git@b939bc96b7ff0645da19c2ff960ac9bd0a50bee7#egg=django_stubs
django-stubs>=1.2.0
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ max-line-length = 88
# https://github.com/PyCQA/pyflakes/issues/475
# see this discussion as to why we're ignoring E722
# https://github.com/PyCQA/pycodestyle/issues/703
extend-ignore = F403 E265 E722 F821
extend-ignore = E722 F821

[mypy]
python_version = 3.4
Expand Down

0 comments on commit f37dd1f

Please sign in to comment.