Skip to content

Commit 5f985a8

Browse files
committed
ci: fix
1 parent 701d83f commit 5f985a8

File tree

8 files changed

+2277
-1518
lines changed

8 files changed

+2277
-1518
lines changed

examples/in_memory/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from starlette.requests import Request
1313
from starlette.responses import JSONResponse, Response
1414

15+
1516
@asynccontextmanager
1617
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
1718
FastAPICache.init(InMemoryBackend())
@@ -64,7 +65,7 @@ async def get_kwargs(name: str):
6465

6566

6667
@app.get("/sync-me")
67-
@cache(namespace="test")
68+
@cache(namespace="test") # pyright: ignore[reportArgumentType]
6869
def sync_me():
6970
# as per the fastapi docs, this sync function is wrapped in a thread,
7071
# thereby converted to async. fastapi-cache does the same.
@@ -125,7 +126,7 @@ async def cached_put():
125126

126127

127128
@app.get("/namespaced_injection")
128-
@cache(namespace="test", expire=5, injected_dependency_namespace="monty_python")
129+
@cache(namespace="test", expire=5, injected_dependency_namespace="monty_python") # pyright: ignore[reportArgumentType]
129130
def namespaced_injection(
130131
__fastapi_cache_request: int = 42, __fastapi_cache_response: int = 17
131132
) -> Dict[str, int]:

examples/redis/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pyright: reportGeneralTypeIssues=false
2-
from contextlib import asynccontextmanager
32
import time
3+
from contextlib import asynccontextmanager
44
from typing import AsyncIterator
55

66
import pendulum
@@ -19,6 +19,7 @@
1919
import redis.asyncio as redis
2020
from redis.asyncio.connection import ConnectionPool
2121

22+
2223
@asynccontextmanager
2324
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
2425
pool = ConnectionPool.from_url(url="redis://redis")
@@ -65,7 +66,7 @@ async def get_data(request: Request, response: Response):
6566
# Note: This function MUST be sync to demonstrate fastapi-cache's correct handling,
6667
# i.e. running cached sync functions in threadpool just like FastAPI itself!
6768
@app.get("/blocking")
68-
@cache(namespace="test", expire=10)
69+
@cache(namespace="test", expire=10) # pyright: ignore[reportArgumentType]
6970
def blocking():
7071
time.sleep(2)
7172
return {"ret": 42}

fastapi_cache/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1+
from importlib.metadata import version
12
from typing import ClassVar, Optional, Type
23

3-
# Because this project supports python 3.7 and up, Pyright treats importlib as
4-
# an external library and so needs to be told to ignore the type issues it sees.
5-
try:
6-
# Python 3.8+
7-
from importlib.metadata import version # type: ignore
8-
except ImportError:
9-
# Python 3.7
10-
from importlib_metadata import version # type: ignore
11-
124
from fastapi_cache.coder import Coder, JsonCoder
135
from fastapi_cache.key_builder import default_key_builder
146
from fastapi_cache.types import Backend, KeyBuilder

fastapi_cache/coder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class ModelField:
2929

3030
CONVERTERS: Dict[str, Callable[[str], Any]] = {
3131
# Pendulum 3.0.0 adds parse to __all__, at which point these ignores can be removed
32-
"date": lambda x: pendulum.parse(x, exact=True), # type: ignore[attr-defined]
33-
"datetime": lambda x: pendulum.parse(x, exact=True), # type: ignore[attr-defined]
32+
"date": lambda x: pendulum.parse(x, exact=True),
33+
"datetime": lambda x: pendulum.parse(x, exact=True),
3434
"decimal": Decimal,
3535
}
3636

fastapi_cache/decorator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def cache(
9393
) -> Callable[[Callable[P, Awaitable[R]]], Callable[P, Awaitable[Union[R, Response]]]]:
9494
"""
9595
cache all function
96+
:param injected_dependency_namespace:
9697
:param namespace:
9798
:param expire:
9899
:param coder:

poetry.lock

Lines changed: 2241 additions & 1477 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fastapi-cache2"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
description = "Cache for FastAPI"
55
authors = ["long2ice <[email protected]>"]
66
license = "Apache-2.0"
@@ -15,22 +15,22 @@ packages = [
1515
include = ["LICENSE", "README.md"]
1616

1717
[tool.poetry.dependencies]
18-
python = "^3.7"
18+
python = "^3.8"
1919
fastapi = "*"
2020
uvicorn = "*"
2121
redis = { version = "^4.2.0rc1", optional = true }
22-
aiomcache = { version = "*", optional = true }
23-
pendulum = "*"
24-
aiobotocore = { version = ">=1.4.1,<3.0.0", optional = true }
2522
typing-extensions = { version = ">=4.1.0" }
26-
importlib-metadata = {version = "^6.6.0", python = "<3.8"}
23+
importlib-metadata = { version = "^6.6.0", python = "<3.8" }
24+
pendulum = "^3.0.0"
25+
aiomcache = { version = "^0.8.2", optional = true }
26+
aiobotocore = {version = "^2.13.1", optional = true}
2727

2828
[tool.poetry.group.linting]
2929
optional = true
3030

3131
[tool.poetry.group.linting.dependencies]
3232
mypy = { version = "^1.2.0", python = "^3.10" }
33-
pyright = { version = "^1.1.306", python = "^3.10" }
33+
pyright = { version = "^1.1.373", python = "^3.10" }
3434
types-aiobotocore = { extras = ["dynamodb"], version = "^2.5.0.post2", python = "^3.10" }
3535
types-redis = { version = "^4.5.4.2", python = "^3.10" }
3636
ruff = { version = ">=0.0.267,<0.1.2", python = "^3.10" }
@@ -57,7 +57,7 @@ all = ["redis", "aiomcache", "aiobotocore"]
5757

5858
[tool.mypy]
5959
files = ["."]
60-
python_version = "3.7"
60+
python_version = "3.8"
6161
# equivalent of --strict
6262
warn_unused_configs = true
6363
disallow_any_generics = true
@@ -72,7 +72,7 @@ warn_unused_ignores = true
7272
warn_return_any = true
7373
no_implicit_reexport = true
7474
strict_equality = true
75-
strict_concatenate = true
75+
extra_checks = true
7676

7777
[[tool.mypy.overrides]]
7878
module = "examples.*.main"
@@ -90,7 +90,7 @@ issue_format = "[#{issue}](https://github.com/long2ice/fastapi-cache/issues/{iss
9090

9191
[tool.pyright]
9292
strict = ["fastapi_cache", "tests"]
93-
pythonVersion = "3.7"
93+
pythonVersion = "3.8"
9494

9595
[tool.pytest.ini_options]
9696
addopts = "-p no:warnings"
@@ -99,16 +99,16 @@ addopts = "-p no:warnings"
9999
ignore = ["E501"]
100100
line-length = 80
101101
select = [
102-
"B", # flake8-bugbear
102+
"B", # flake8-bugbear
103103
"C4", # flake8-comprehensions
104-
"E", # pycodestyle errors
105-
"F", # pyflakes
106-
"I", # isort
107-
"S", # flake8-bandit
108-
"W", # pycodestyle warnings
104+
"E", # pycodestyle errors
105+
"F", # pyflakes
106+
"I", # isort
107+
"S", # flake8-bandit
108+
"W", # pycodestyle warnings
109109
"UP", # pyupgrade
110110
]
111-
target-version = "py37"
111+
target-version = "py38"
112112

113113
[build-system]
114114
requires = ["poetry-core"]

tests/test_decorator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,39 @@ def test_datetime() -> None:
2222
response = client.get("/datetime")
2323
assert response.headers.get("X-FastAPI-Cache") == "MISS"
2424
now = response.json().get("now")
25-
now_ = pendulum.now().replace(microsecond=0) # type: ignore[no-untyped-call]
26-
assert pendulum.parse(now).replace(microsecond=0) == now_ # type: ignore[attr-defined]
25+
now_ = pendulum.now()
26+
assert pendulum.parse(now) == now_
2727
response = client.get("/datetime")
2828
assert response.headers.get("X-FastAPI-Cache") == "HIT"
2929
now = response.json().get("now")
30-
assert pendulum.parse(now).replace(microsecond=0) == now_ # type: ignore[attr-defined]
30+
assert pendulum.parse(now) == now_
3131
time.sleep(3)
3232
response = client.get("/datetime")
3333
now = response.json().get("now")
3434
assert response.headers.get("X-FastAPI-Cache") == "MISS"
35-
now = pendulum.parse(now).replace(microsecond=0) # type: ignore[attr-defined]
35+
now = pendulum.parse(now)
3636
assert now != now_
37-
assert now == pendulum.now().replace(microsecond=0) # type: ignore[no-untyped-call]
37+
assert now == pendulum.now()
3838

3939

4040
def test_date() -> None:
4141
"""Test path function without request or response arguments."""
4242
with TestClient(app) as client:
4343
response = client.get("/date")
4444
assert response.headers.get("X-FastAPI-Cache") == "MISS"
45-
assert pendulum.parse(response.json()) == pendulum.today() # type: ignore[attr-defined]
45+
assert pendulum.parse(response.json()) == pendulum.today()
4646

4747
# do it again to test cache
4848
response = client.get("/date")
4949
assert response.headers.get("X-FastAPI-Cache") == "HIT"
50-
assert pendulum.parse(response.json()) == pendulum.today() # type: ignore[attr-defined]
50+
assert pendulum.parse(response.json()) == pendulum.today()
5151

5252
# now test with cache disabled, as that's a separate code path
5353
FastAPICache._enable = False # pyright: ignore[reportPrivateUsage]
5454
response = client.get("/date")
5555
assert "X-FastAPI-Cache" not in response.headers
56-
assert pendulum.parse(response.json()) == pendulum.today() # type: ignore[attr-defined]
57-
FastAPICache._enable = True # pyright: ignore[reportPrivateUsage]
56+
assert pendulum.parse(response.json()) == pendulum.today()
57+
FastAPICache._enable = True # pyright: ignore[reportPrivateUsage]
5858

5959

6060
def test_sync() -> None:

0 commit comments

Comments
 (0)