feat: add type hints everywhere

This commit is contained in:
Gabriel Dugny 2024-03-24 23:29:52 +01:00
parent c11f30ec7c
commit b9f4e596a4
12 changed files with 138 additions and 98 deletions

View file

@ -1,4 +1,5 @@
from enum import Enum
from typing import List
from django.conf import settings
@ -9,27 +10,27 @@ class ContextBehavior(Enum):
class AppSettings:
def __init__(self):
def __init__(self) -> None:
self.settings = getattr(settings, "COMPONENTS", {})
@property
def AUTODISCOVER(self):
def AUTODISCOVER(self) -> bool:
return self.settings.setdefault("autodiscover", True)
@property
def LIBRARIES(self):
def LIBRARIES(self) -> List:
return self.settings.setdefault("libraries", [])
@property
def TEMPLATE_CACHE_SIZE(self):
def TEMPLATE_CACHE_SIZE(self) -> int:
return self.settings.setdefault("template_cache_size", 128)
@property
def CONTEXT_BEHAVIOR(self):
def CONTEXT_BEHAVIOR(self) -> ContextBehavior:
raw_value = self.settings.setdefault("context_behavior", ContextBehavior.GLOBAL.value)
return self._validate_context_behavior(raw_value)
def _validate_context_behavior(self, raw_value):
def _validate_context_behavior(self, raw_value: ContextBehavior) -> ContextBehavior:
try:
return ContextBehavior(raw_value)
except ValueError: