Skip to content

Commit f031284

Browse files
committed
[FIX] Apply linting recommendations in 18
1 parent 359e197 commit f031284

4 files changed

Lines changed: 23 additions & 14 deletions

File tree

fastapi/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
"""
1111

12-
from typing import Iterable
12+
from collections.abc import Iterable
1313

1414
import a2wsgi
1515
from a2wsgi.asgi import ASGIResponder

fastapi/models/fastapi_endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _registered_endpoint_rule_keys(self):
121121
return tuple(res)
122122

123123
@api.model
124-
def _routing_impacting_fields(self) -> Tuple[str, ...]:
124+
def _routing_impacting_fields(self) -> tuple[str, ...]:
125125
"""The list of fields requiring to refresh the mount point of the pp
126126
into odoo if modified"""
127127
return ("root_path", "save_http_session")

fastapi/pools/event_loop.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import asyncio
55
import queue
66
import threading
7+
from collections.abc import Generator
78
from contextlib import contextmanager
8-
from typing import Generator
99

1010

1111
class EventLoopPool:
@@ -16,7 +16,8 @@ def __get_event_loop_and_thread(
1616
self,
1717
) -> tuple[asyncio.AbstractEventLoop, threading.Thread]:
1818
"""
19-
Get an event loop from the pool. If no event loop is available, create a new one.
19+
Get an event loop from the pool. If no event loop is available,
20+
create a new one.
2021
"""
2122
try:
2223
return self.pool.get_nowait()
@@ -47,9 +48,11 @@ def shutdown(self):
4748
@contextmanager
4849
def get_event_loop(self) -> Generator[asyncio.AbstractEventLoop, None, None]:
4950
"""
50-
Get an event loop from the pool. If no event loop is available, create a new one.
51+
Get an event loop from the pool. If no event loop is available,
52+
create a new one.
5153
52-
After the context manager exits, the event loop is returned to the pool for reuse.
54+
After the context manager exits, the event loop is returned to
55+
the pool for reuse.
5356
"""
5457
loop, thread = self.__get_event_loop_and_thread()
5558
try:

fastapi/pools/fastapi_app.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import queue
55
import threading
66
from collections import defaultdict
7+
from collections.abc import Generator
78
from contextlib import contextmanager
8-
from typing import Generator
99

1010
from odoo.api import Environment
1111

@@ -45,8 +45,8 @@ class FastApiAppPool:
4545
updated by the increment of the `cache_sequence` SQL sequence. This cache sequence
4646
on the registry is reloaded from the DB on each request made to a specific database.
4747
When an app is retrieved from the pool, we always compare the cache sequence of
48-
the pool with the cache sequence of the registry. If the two sequences are different,
49-
we invalidate the pool and save the new cache sequence on the pool.
48+
the pool with the cache sequence of the registry. If the two sequences are
49+
different, we invalidate the pool and save the new cache sequence on the pool.
5050
5151
The cache is based on a defaultdict of defaultdict of queue.Queue. We are cautious
5252
that the use of defaultdict is not thread-safe for operations that modify the
@@ -61,9 +61,9 @@ class FastApiAppPool:
6161
"""
6262

6363
def __init__(self):
64-
self._queue_by_db_by_root_path: dict[
65-
str, dict[str, queue.Queue[FastAPI]]
66-
] = defaultdict(lambda: defaultdict(queue.Queue))
64+
self._queue_by_db_by_root_path: dict[str, dict[str, queue.Queue[FastAPI]]] = (
65+
defaultdict(lambda: defaultdict(queue.Queue))
66+
)
6767
self.__cache_sequences = {}
6868
self._lock = threading.Lock()
6969

@@ -108,13 +108,19 @@ def get_cache_sequence(self, key: str) -> int:
108108

109109
def set_cache_sequence(self, key: str, value: int) -> None:
110110
with self._lock:
111-
if key not in self.__cache_sequences or value != self.__cache_sequences[key]:
111+
if (
112+
key not in self.__cache_sequences
113+
or value != self.__cache_sequences[key]
114+
):
112115
self.__cache_sequences[key] = value
113116

114117
def _check_cache(self, env: Environment) -> None:
115118
cache_sequences = env.registry.cache_sequences
116119
for key, value in cache_sequences.items():
117-
if value != self.get_cache_sequence(key) and self.get_cache_sequence(key) != 0:
120+
if (
121+
value != self.get_cache_sequence(key)
122+
and self.get_cache_sequence(key) != 0
123+
):
118124
_logger.info(
119125
"Cache registry updated, reset fastapi_app pool for the current "
120126
"database"

0 commit comments

Comments
 (0)