refactor: improve config loader validation with Pydantic schemas

- Replace manual field type validation with Pydantic model schemas
- Add pydantic>=2.0 as core dependency
- Fix sync wrapper in decorator to properly handle rate limiting
- Update pyright settings for stricter type checking
- Fix repository URL in pyproject.toml
- Remove unused main.py
- Update test assertions for new validation error format
This commit is contained in:
2026-03-07 15:43:25 +00:00
parent 4f19c0b19e
commit 492410614f
10 changed files with 200 additions and 148 deletions

View File

@@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, TypeAlias
from fastapi_traffic.core.algorithms import Algorithm
@@ -14,7 +14,7 @@ if TYPE_CHECKING:
from fastapi_traffic.backends.base import Backend
KeyExtractor = Callable[["Request"], str]
KeyExtractor: TypeAlias = Callable[["Request"], str]
def default_key_extractor(request: Request) -> str:
@@ -55,10 +55,10 @@ class RateLimitConfig:
if self.limit <= 0:
msg = "limit must be positive"
raise ValueError(msg)
if self.window_size <= 0:
elif self.window_size <= 0:
msg = "window_size must be positive"
raise ValueError(msg)
if self.cost <= 0:
elif self.cost <= 0:
msg = "cost must be positive"
raise ValueError(msg)