Skip to content

Commit 80d2fd4

Browse files
committed
Clarify API boundaries and remove cast
This avoids needing to cast the settings by instead documenting the expected bounds of the API offered.
1 parent c8e1502 commit 80d2fd4

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

django_lightweight_queue/app_settings.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
Internal API facade over Django settings.
3+
4+
This provides a typed interface over Django settings as well as handling default
5+
values for settings not set by users and supporting the addition of overrides in
6+
some management commands.
7+
"""
8+
19
from typing import Any, Dict, List, Union, Callable, Optional, Sequence
210

311
from typing_extensions import Protocol
@@ -45,6 +53,11 @@ class Settings(Protocol):
4553
ATOMIC_JOBS: bool
4654

4755

56+
class LayeredSettings(Settings, Protocol):
57+
def add_layer(self, layer: Settings) -> None:
58+
...
59+
60+
4861
class Defaults(Settings):
4962
WORKERS: Dict[QueueName, int] = {}
5063
BACKEND = 'django_lightweight_queue.backends.synchronous.SynchronousBackend'
@@ -84,7 +97,7 @@ def __getattr__(self, name: str) -> Any:
8497
raise AttributeError(f"Sorry, '{name}' is not a valid setting.")
8598

8699

87-
app_settings: Settings = AppSettings(layers=[
100+
app_settings: LayeredSettings = AppSettings(layers=[
88101
Defaults(),
89102
LongNameAdapter(django_settings),
90103
])

django_lightweight_queue/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from . import constants
2525
from .types import Logger, QueueName, WorkerNumber
26-
from .app_settings import Defaults, AppSettings, app_settings, LongNameAdapter
26+
from .app_settings import Defaults, app_settings, LongNameAdapter
2727

2828
if TYPE_CHECKING:
2929
from .backends.base import BaseBackend
@@ -56,7 +56,7 @@ def with_prefix(names: Iterable[str]) -> Set[str]:
5656
unexpected_str = "' ,'".join(unexpected_names)
5757
warnings.warn("Ignoring unexpected setting(s) '{}'.".format(unexpected_str))
5858

59-
cast(AppSettings, app_settings).add_layer(LongNameAdapter(extra_settings))
59+
app_settings.add_layer(LongNameAdapter(extra_settings))
6060

6161

6262
@lru_cache()

0 commit comments

Comments
 (0)