style: apply ruff formatting
This commit is contained in:
@@ -49,12 +49,14 @@ _GLOBAL_FIELD_TYPES: dict[str, type[Any]] = {
|
||||
}
|
||||
|
||||
# Fields that cannot be loaded from config files (callables, complex objects)
|
||||
_NON_LOADABLE_FIELDS: frozenset[str] = frozenset({
|
||||
"key_extractor",
|
||||
"exempt_when",
|
||||
"on_blocked",
|
||||
"backend",
|
||||
})
|
||||
_NON_LOADABLE_FIELDS: frozenset[str] = frozenset(
|
||||
{
|
||||
"key_extractor",
|
||||
"exempt_when",
|
||||
"on_blocked",
|
||||
"backend",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class ConfigLoader:
|
||||
@@ -200,7 +202,11 @@ class ConfigLoader:
|
||||
value = value.strip()
|
||||
|
||||
# Remove surrounding quotes if present
|
||||
if len(value) >= 2 and value[0] == value[-1] and value[0] in ('"', "'"):
|
||||
if (
|
||||
len(value) >= 2
|
||||
and value[0] == value[-1]
|
||||
and value[0] in ('"', "'")
|
||||
):
|
||||
value = value[1:-1]
|
||||
|
||||
env_vars[key] = value
|
||||
@@ -261,7 +267,7 @@ class ConfigLoader:
|
||||
|
||||
for key, value in source.items():
|
||||
if key.startswith(full_prefix):
|
||||
field_name = key[len(full_prefix):].lower()
|
||||
field_name = key[len(full_prefix) :].lower()
|
||||
if field_name in field_types:
|
||||
result[field_name] = value
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ F = TypeVar("F", bound=Callable[..., Any])
|
||||
|
||||
# Note: Config loader from secrets .env
|
||||
|
||||
|
||||
@overload
|
||||
def rate_limit(
|
||||
limit: int,
|
||||
|
||||
@@ -24,6 +24,7 @@ from fastapi_traffic.middleware import RateLimitMiddleware
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -143,9 +143,7 @@ class TestConfigLoaderEnv:
|
||||
assert config.exempt_ips == {"127.0.0.1", "192.168.1.1", "10.0.0.1"}
|
||||
assert config.exempt_paths == {"/health", "/metrics"}
|
||||
|
||||
def test_load_global_config_from_env_empty_sets(
|
||||
self, loader: ConfigLoader
|
||||
) -> None:
|
||||
def test_load_global_config_from_env_empty_sets(self, loader: ConfigLoader) -> None:
|
||||
"""Test loading GlobalConfig with empty set fields."""
|
||||
env_vars = {
|
||||
"FASTAPI_TRAFFIC_GLOBAL_EXEMPT_IPS": "",
|
||||
|
||||
Reference in New Issue
Block a user