mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
Typing cleanup
- Compatibility with older Python versions - use `Optional` and `Union` instead of `... | None` and `a | b` - use `typing_extensions.Protocol` instead of `typing.Protocol` - use `typing.Dict`, `typing.List`, etc. instead of the concrete types. - Fix backend `.get()` annotations; not all were marked as `Optional[str]` - Don't return anything from `Backend.set()` methods. - The `Coder.decode_as_type()` type parameter must be a type to be compatible with `ModelField(..., type_=...)`. - Clean up `Optional[]` use, remove where it is not needed. - Clean up variable use in decorator, keeping the raw cached value separate from the return value from the wrapped endpoint. - Annotate the wrapper as returning either the original type _or_ a Response (returning a 304 Not Modified response). - Clean up small edge-case where `response` could be `None`. - Correct type annotation on `JsonCoder.decode()` to match `Coder.decode()`.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel, ValidationError
|
||||
@@ -46,7 +46,7 @@ def test_pickle_coder(value: Any) -> None:
|
||||
[
|
||||
(1, None),
|
||||
("some_string", None),
|
||||
((1, 2), tuple[int, int]),
|
||||
((1, 2), Tuple[int, int]),
|
||||
([1, 2, 3], None),
|
||||
({"some_key": 1, "other_key": 2}, None),
|
||||
(DCItem(name="foo", price=42.0, description="some dataclass item", tax=0.2), DCItem),
|
||||
|
||||
Reference in New Issue
Block a user