Skip to content

Commit fecaee9

Browse files
Berik AshimovBerik Ashimov
authored andcommitted
build: rename _is_trivial -> _trivial to avoid MSVC __is_trivial reserved C++ trait
1 parent 70c3f9f commit fecaee9

4 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/hawkapi/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ async def _execute_trivial_route(
565565
"""Minimal hot path for routes with no DI/deps/perms/bg-tasks/deprecation.
566566
567567
Skips all bookkeeping that _execute_route does. Only safe to call when
568-
route._is_trivial is True (guaranteed by _compute_is_trivial at
568+
route._trivial is True (guaranteed by _compute_trivial at
569569
registration time). Handles Request-only and no-arg handlers via the
570570
pre-computed plan.kwargs_specs via ParamSource.REQUEST detection.
571571
"""
@@ -634,7 +634,7 @@ async def _execute_trivial_route(
634634

635635
# Minimal HEAD handling: zero out the body but keep content-length.
636636
# StreamingResponse is not a Response subclass — fall back to the
637-
# general path if somehow one slips through (guards _is_trivial calc).
637+
# general path if somehow one slips through (guards _trivial calc).
638638
if isinstance(response, StreamingResponse):
639639
await self._execute_route(scope, receive, send, route, plan, request)
640640
return
@@ -911,7 +911,7 @@ async def _core_handler_inner(self, scope: Scope, receive: Receive, send: Send)
911911
# stack, background tasks, HEAD special-case, deprecation headers,
912912
# permissions, timeout wrapping). The flag is computed once at
913913
# registration time — no per-request isinstance/attribute checks.
914-
if route._is_trivial: # pyright: ignore[reportPrivateUsage]
914+
if route._trivial: # pyright: ignore[reportPrivateUsage]
915915
await self._execute_trivial_route(scope, receive, send, route, plan, request)
916916
return
917917

src/hawkapi/routing/route.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ class Route:
4242
# no permissions, no background tasks, is async, returns a Response
4343
# directly, and is not deprecated. Set once at registration time by the
4444
# router so the per-request hot path avoids branching on all these checks.
45-
_is_trivial: bool = field(default=False, repr=False)
45+
_trivial: bool = field(default=False, repr=False)

src/hawkapi/routing/router.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
)
3434

3535

36-
def _compute_is_trivial(
36+
def _compute_trivial(
3737
plan: Any,
3838
response_model: type[Any] | None,
3939
permissions: list[str] | None,
@@ -239,7 +239,7 @@ def add_route(
239239
dependencies=dep_plans,
240240
required_scopes=required_scopes,
241241
_handler_plan=plan,
242-
_is_trivial=_compute_is_trivial(
242+
_trivial=_compute_trivial(
243243
plan,
244244
response_model,
245245
permissions,
@@ -601,7 +601,7 @@ def include_router(self, router: Router) -> None:
601601
dependencies=merged_deps,
602602
required_scopes=merged_required,
603603
_handler_plan=plan,
604-
_is_trivial=_compute_is_trivial(
604+
_trivial=_compute_trivial(
605605
plan,
606606
route.response_model,
607607
route.permissions,

tests/unit/test_trivial_route.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Unit tests for the trivial-route fast-path classification.
22
3-
Verifies that ``route._is_trivial`` is True for simple async handlers that
3+
Verifies that ``route._trivial`` is True for simple async handlers that
44
return a Response directly, and False whenever any feature that requires the
55
full ``_execute_route`` path is present (DI, deps, perms, bg-tasks, etc.).
66
@@ -49,7 +49,7 @@ async def handler() -> Response:
4949
return Response(b"pong")
5050

5151
route = _get_route(app, "/ping")
52-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
52+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
5353

5454
def test_request_only_param(self) -> None:
5555
"""Handler that only takes Request is trivial."""
@@ -60,7 +60,7 @@ async def handler(request: Request) -> Response:
6060
return PlainTextResponse("hi")
6161

6262
route = _get_route(app, "/hello")
63-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
63+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
6464

6565
def test_path_param_only(self) -> None:
6666
"""Handler with a single path param is trivial."""
@@ -71,7 +71,7 @@ async def handler(item_id: str) -> Response:
7171
return Response(item_id.encode())
7272

7373
route = _get_route(app, "/items/{item_id}")
74-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
74+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
7575

7676
def test_query_param_with_default(self) -> None:
7777
"""Handler with a plain query param default is trivial."""
@@ -82,7 +82,7 @@ async def handler(q: str = "") -> Response:
8282
return Response(q.encode())
8383

8484
route = _get_route(app, "/search")
85-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
85+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
8686

8787
def test_json_response_return(self) -> None:
8888
"""Handler returning JSONResponse is trivial."""
@@ -93,7 +93,7 @@ async def handler() -> JSONResponse:
9393
return JSONResponse({"ok": True})
9494

9595
route = _get_route(app, "/data")
96-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
96+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
9797

9898

9999
# ---------------------------------------------------------------------------
@@ -111,7 +111,7 @@ def handler() -> Response: # type: ignore[return]
111111
return Response(b"sync")
112112

113113
route = _get_route(app, "/sync")
114-
assert route._is_trivial is False # pyright: ignore[reportPrivateUsage]
114+
assert route._trivial is False # pyright: ignore[reportPrivateUsage]
115115

116116
def test_depends_callable_not_trivial(self) -> None:
117117
"""Routes with Depends() callable injection are NOT trivial."""
@@ -125,7 +125,7 @@ async def handler(val: Annotated[str, Depends(my_dep)]) -> Response:
125125
return Response(val.encode())
126126

127127
route = _get_route(app, "/dep")
128-
assert route._is_trivial is False # pyright: ignore[reportPrivateUsage]
128+
assert route._trivial is False # pyright: ignore[reportPrivateUsage]
129129

130130
def test_permissions_not_trivial(self) -> None:
131131
"""Routes with permissions are NOT trivial."""
@@ -136,7 +136,7 @@ async def handler() -> Response:
136136
return Response(b"secure")
137137

138138
route = _get_route(app, "/secure")
139-
assert route._is_trivial is False # pyright: ignore[reportPrivateUsage]
139+
assert route._trivial is False # pyright: ignore[reportPrivateUsage]
140140

141141
def test_route_level_dependencies_not_trivial(self) -> None:
142142
"""Routes with side-effect dependencies=[Depends(...)] are NOT trivial."""
@@ -150,7 +150,7 @@ async def handler() -> Response:
150150
return Response(b"guarded")
151151

152152
route = _get_route(app, "/guarded")
153-
assert route._is_trivial is False # pyright: ignore[reportPrivateUsage]
153+
assert route._trivial is False # pyright: ignore[reportPrivateUsage]
154154

155155
def test_background_tasks_not_trivial(self) -> None:
156156
"""Routes injecting BackgroundTasks are NOT trivial."""
@@ -161,7 +161,7 @@ async def handler(bg: BackgroundTasks) -> Response:
161161
return Response(b"bg")
162162

163163
route = _get_route(app, "/bg")
164-
assert route._is_trivial is False # pyright: ignore[reportPrivateUsage]
164+
assert route._trivial is False # pyright: ignore[reportPrivateUsage]
165165

166166
def test_response_model_not_trivial(self) -> None:
167167
"""Routes with an explicit response_model are NOT trivial."""
@@ -177,7 +177,7 @@ async def handler() -> Item:
177177
return Item(name="x")
178178

179179
route = _get_route(app, "/item")
180-
assert route._is_trivial is False # pyright: ignore[reportPrivateUsage]
180+
assert route._trivial is False # pyright: ignore[reportPrivateUsage]
181181

182182
def test_deprecated_not_trivial(self) -> None:
183183
"""Deprecated routes are NOT trivial (need deprecation headers)."""
@@ -188,7 +188,7 @@ async def handler() -> Response:
188188
return Response(b"old")
189189

190190
route = _get_route(app, "/old")
191-
assert route._is_trivial is False # pyright: ignore[reportPrivateUsage]
191+
assert route._trivial is False # pyright: ignore[reportPrivateUsage]
192192

193193
def test_exclude_none_not_trivial(self) -> None:
194194
"""Routes with response_model_exclude_none are NOT trivial."""
@@ -199,7 +199,7 @@ async def handler() -> dict: # type: ignore[return]
199199
return {"a": 1, "b": None}
200200

201201
route = _get_route(app, "/filtered")
202-
assert route._is_trivial is False # pyright: ignore[reportPrivateUsage]
202+
assert route._trivial is False # pyright: ignore[reportPrivateUsage]
203203

204204

205205
# ---------------------------------------------------------------------------
@@ -219,7 +219,7 @@ async def handler() -> Response:
219219
return PlainTextResponse("Hello, World!")
220220

221221
route = _get_route(app, "/hello")
222-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
222+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
223223

224224
client = TestClient(app)
225225
resp = client.get("/hello")
@@ -237,7 +237,7 @@ async def handler(request: Request) -> Response:
237237
return PlainTextResponse(request.path)
238238

239239
route = _get_route(app, "/echo-path")
240-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
240+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
241241

242242
client = TestClient(app)
243243
resp = client.get("/echo-path")
@@ -254,7 +254,7 @@ async def handler(name: str = "world") -> Response:
254254
return PlainTextResponse(f"hello {name}")
255255

256256
route = _get_route(app, "/greet")
257-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
257+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
258258

259259
client = TestClient(app)
260260
assert client.get("/greet").text == "hello world"
@@ -272,7 +272,7 @@ async def handler() -> Response:
272272
raise HTTPException(status_code=403, detail="Forbidden")
273273

274274
route = _get_route(app, "/fail")
275-
assert route._is_trivial is True # pyright: ignore[reportPrivateUsage]
275+
assert route._trivial is True # pyright: ignore[reportPrivateUsage]
276276

277277
client = TestClient(app)
278278
resp = client.get("/fail")

0 commit comments

Comments
 (0)