Skip to content

Commit 2ddd8b4

Browse files
committed
Remove typing.Optional in favor of union types
1 parent 92f5d96 commit 2ddd8b4

7 files changed

Lines changed: 12 additions & 21 deletions

File tree

debug_toolbar/panels/logging.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,20 @@ def __init__(self) -> None:
2626
)
2727
self.collections: dict[int, list[dict[str, t.Any]]] = {}
2828

29-
def get_collection(
30-
self,
31-
thread_id: t.Optional[int] = None,
32-
) -> list[dict[str, t.Any]]:
29+
def get_collection(self, thread_id: int | None = None) -> list[dict[str, t.Any]]:
3330
if thread_id is None:
3431
thread_id = threading.get_ident()
3532
if thread_id not in self.collections:
3633
self.collections[thread_id] = []
3734
return self.collections[thread_id]
3835

39-
def clear_collection(self, thread_id: t.Optional[int] = None) -> None:
36+
def clear_collection(self, thread_id: int | None = None) -> None:
4037
if thread_id is None:
4138
thread_id = threading.get_ident()
4239
if thread_id in self.collections:
4340
del self.collections[thread_id]
4441

45-
def collect(
46-
self,
47-
item: dict[str, t.Any],
48-
thread_id: t.Optional[int] = None,
49-
) -> None:
42+
def collect(self, item: dict[str, t.Any], thread_id: int | None = None) -> None:
5043
self.get_collection(thread_id).append(item)
5144

5245

debug_toolbar/panels/tortoise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def execute_insert(self, query: str, values: list) -> t.Any:
3030
async def execute_query(
3131
self,
3232
query: str,
33-
values: t.Optional[list] = None,
33+
values: list | None = None,
3434
) -> tuple[int, t.Sequence[dict]]:
3535
with self.on_execute(self.db, query, values):
3636
return await self.db.execute_query(query, values)
@@ -46,7 +46,7 @@ async def execute_many(self, query: str, values: list[list]) -> None:
4646
async def execute_query_dict(
4747
self,
4848
query: str,
49-
values: t.Optional[list] = None,
49+
values: list | None = None,
5050
) -> list[dict]:
5151
with self.on_execute(self.db, query, values):
5252
return await self.db.execute_query_dict(query, values)

debug_toolbar/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DebugToolbarSettings(BaseSettings):
4747
"want disabled (but still displayed) by default."
4848
),
4949
)
50-
ALLOWED_HOSTS: t.Optional[t.Sequence[str]] = Field(
50+
ALLOWED_HOSTS: t.Sequence[str] | None = Field(
5151
None,
5252
description=(
5353
"If it's set, the Debug Toolbar is shown only "

debug_toolbar/toolbar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
class DebugToolbar:
2323
_store: "StoreDT" = OrderedDict()
24-
_panel_classes: t.Optional[t.Sequence[t.Type[Panel]]] = None
24+
_panel_classes: t.Sequence[t.Type[Panel]] | None = None
2525

2626
def __init__(
2727
self,
@@ -51,7 +51,7 @@ def __init__(
5151

5252
self.stats: Stats = {}
5353
self.server_timing_stats: dict[str, ServerTiming] = {}
54-
self.store_id: t.Optional[str] = None
54+
self.store_id: str | None = None
5555

5656
@classmethod
5757
def get_panel_classes(
@@ -84,7 +84,7 @@ def store(self) -> None:
8484
self._store.popitem(last=False)
8585

8686
@classmethod
87-
def fetch(cls: t.Type[DT], store_id: str) -> t.Optional[DT]:
87+
def fetch(cls: t.Type[DT], store_id: str) -> DT | None:
8888
return cls._store.get(store_id)
8989

9090
async def record_stats(self, response: Response) -> None:

debug_toolbar/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_name_from_obj(obj: t.Any) -> str:
3838
return name
3939

4040

41-
def matched_route(request: Request) -> t.Optional[APIRoute]:
41+
def matched_route(request: Request) -> APIRoute | None:
4242
for route in request.app.routes:
4343
match, _ = route.matches(request.scope)
4444

tests/panels/sqlalchemy/crud.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import typing as t
2-
31
from sqlalchemy import Column
42
from sqlalchemy.orm import Session
53

@@ -13,7 +11,7 @@ def create_user(db: Session, username: str) -> models.User:
1311
return user
1412

1513

16-
def get_user(db: Session, user_id: Column[int]) -> t.Optional[models.User]:
14+
def get_user(db: Session, user_id: Column[int]) -> models.User | None:
1715
query = db.query(models.User).filter(models.User.id == user_id)
1816

1917
if query is not None:

tests/testclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TestClient(BaseTestClient):
1414
def get_store_id(
1515
self,
1616
path: str,
17-
method: t.Optional[str] = None,
17+
method: str | None = None,
1818
**kwargs: t.Any,
1919
) -> str:
2020
response = getattr(self, (method or "get"))(path, **kwargs)

0 commit comments

Comments
 (0)