1
0
mirror of https://github.com/enpaul/kodak.git synced 2025-11-09 20:22:31 +00:00

Fix typing errors

Fix missing dependencies in static tox envs
This commit is contained in:
2021-10-30 11:51:41 -04:00
parent 158db1209b
commit 19739d17f4
8 changed files with 37 additions and 13 deletions

View File

@@ -136,7 +136,7 @@ class ManipCropConfig:
def from_env(cls, key: str):
"""Build dataclass from environment"""
return cls(
anchor=_get_enum_by_value(
anchor=_get_enum_by_value( # type: ignore
f"KODAK_MANIP_{key}_CROP_ANCHOR", constants.CropAnchor, cls.anchor
),
horizontal=_get_int(f"KODAK_MANIP_{key}_CROP_HORIZONTAL", cls.horizontal),
@@ -173,16 +173,16 @@ class ManipScaleConfig:
)
if strategy == constants.ScaleStrategy.ABSOLUTE:
parser = _get_int
parser = _get_int # type: ignore
elif strategy == constants.ScaleStrategy.RELATIVE:
parser = _get_float
parser = _get_float # type: ignore
else:
raise RuntimeError("This path should not be possible")
return cls(
strategy=strategy,
vertical=parser(f"KODAK_MANIP_{key}_SCALE_VERTICAL", cls.vertical),
horizontal=parser(f"KODAK_MANIP_{key}_SCALE_HORIZONTAL", cls.horizontal),
strategy=strategy, # type: ignore
vertical=parser(f"KODAK_MANIP_{key}_SCALE_VERTICAL", cls.vertical), # type: ignore
horizontal=parser(f"KODAK_MANIP_{key}_SCALE_HORIZONTAL", cls.horizontal), # type: ignore
)
@@ -198,8 +198,8 @@ class ManipConfig:
"""
name: str
crop: ManipCropConfig = field(default_factory=ManipCropConfig.from_env)
scale: ManipScaleConfig = field(default_factory=ManipScaleConfig.from_env)
crop: ManipCropConfig = field(default_factory=ManipCropConfig)
scale: ManipScaleConfig = field(default_factory=ManipScaleConfig)
formats: Set[constants.ImageFormat] = field(
default_factory=lambda: constants.DEFAULT_SUPPORTED_FORMATS
)

View File

@@ -1,5 +1,6 @@
import logging
from typing import Tuple
from typing import Type
import peewee
@@ -13,7 +14,7 @@ from kodak.database.alias import AliasRecord
from kodak.database.image import ImageRecord
MODELS: Tuple[KodakModel, ...] = (ImageRecord, AliasRecord, AccessRecord)
MODELS: Tuple[Type[KodakModel], ...] = (ImageRecord, AliasRecord, AccessRecord)
def initialize(config: KodakConfig):

View File

@@ -1,12 +1,15 @@
import datetime
import enum
import hashlib
import typing
import uuid
from typing import NamedTuple
from typing import Type
import peewee
if typing.TYPE_CHECKING:
import _hashlib
INTERFACE = peewee.DatabaseProxy()
@@ -22,7 +25,7 @@ class Checksum(NamedTuple):
digest: str
@classmethod
def from_hash(cls, data: hashlib._hashlib.HASH): # pylint: disable=protected-access
def from_hash(cls, data: "_hashlib.HASH"):
"""Construct from a hashlib object"""
return cls(algorithm=data.name, digest=data.hexdigest())

View File

@@ -29,6 +29,12 @@ class ImageResourceDeletedError(ClientError):
status = 410
class IAmATeapotError(ClientError):
"""User tried to brew coffee, but application is a teapot"""
status = 418
class ServerError(KodakException):
"""Error while processing server side data"""

View File

@@ -1,4 +1,5 @@
from typing import Tuple
from typing import Type
from kodak.resources._shared import KodakResource
from kodak.resources.alias import ImageAlias
@@ -7,7 +8,7 @@ from kodak.resources.image import Image
from kodak.resources.openapi import OpenAPI
RESOURCES: Tuple[KodakResource, ...] = (
RESOURCES: Tuple[Type[KodakResource], ...] = (
Heartbeat,
Image,
ImageAlias,