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

@@ -51,7 +51,6 @@ def rate_limit(
/,
) -> Callable[[F], F]: ...
def rate_limit(
limit: int,
window_size: float = 60.0,
@@ -139,9 +138,23 @@ def rate_limit(
def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
import asyncio
return asyncio.get_event_loop().run_until_complete(
async_wrapper(*args, **kwargs)
)
async def _sync_rate_limit() -> Any:
request = _extract_request(args, kwargs)
if request is None:
return func(*args, **kwargs)
limiter = get_limiter()
result = await limiter.hit(request, config)
response = func(*args, **kwargs)
if config.include_headers and hasattr(response, "headers"):
for key, value in result.info.to_headers().items():
response.headers[key] = value
return response
return asyncio.get_event_loop().run_until_complete(_sync_rate_limit())
if _is_coroutine_function(func):
return async_wrapper # type: ignore[return-value]