mirror of
https://github.com/django-components/django-components.git
synced 2025-08-10 17:28:00 +00:00
feat: add type hints everywhere
This commit is contained in:
parent
c11f30ec7c
commit
b9f4e596a4
12 changed files with 138 additions and 98 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue