Skip to content

Commit 64e14d1

Browse files
author
Raphael Krupinski
committed
🚨 Fix linter error in processing response annotations.
1 parent 53c8f27 commit 64e14d1

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

‎src/lapidary/runtime/model/op.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import inspect
2-
from collections.abc import Awaitable, Callable, Iterable, Mapping, MutableMapping, Sequence
2+
from collections.abc import Awaitable, Callable, Iterable, Mapping, MutableMapping
33

44
import httpx
55
import pydantic.fields
@@ -164,23 +164,21 @@ def process_response_envelope(typ: type[ResponseEnvelope]) -> Iterable[ResponseH
164164

165165

166166
def process_response_field(name: str, field: pydantic.fields.FieldInfo) -> ResponseHandler:
167-
field_handlers: Sequence[ResponseHandler] = [
168-
anno
169-
for anno in field.metadata
170-
if isinstance(anno, ResponseHandler) or (inspect.isclass(anno) and issubclass(anno, ResponseHandler))
171-
]
172-
if not len(field_handlers) == 1:
167+
field_handlers = []
168+
for anno in field.metadata:
169+
if inspect.isclass(anno) and issubclass(anno, ResponseHandler):
170+
field_handlers.append(anno())
171+
elif isinstance(anno, ResponseHandler):
172+
field_handlers.append(anno)
173+
if len(field_handlers) != 1:
173174
raise TypeError(f'{name}: Expected exactly one ResponseHandler annotation')
174175
handler = field_handlers[0]
175-
if inspect.isclass(handler) and issubclass(handler, ResponseHandler):
176-
handler_inst = typing.cast(type[ResponseHandler], handler)()
177-
else:
178-
handler_inst = handler
179-
if isinstance(handler_inst, NameTypeAwareAnnotation):
176+
177+
if isinstance(handler, NameTypeAwareAnnotation):
180178
field_type = field.annotation
181179
assert field_type
182-
handler_inst.supply_formal(name, field_type)
183-
return handler_inst
180+
handler.supply_formal(name, field_type)
181+
return handler
184182

185183

186184
def find_type(

‎tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def login(body: AuthRequest) -> AuthResponse:
7272

7373

7474
class CatListResponse(ResponseEnvelope):
75-
body: typing.Annotated[typing.List[Cat], ResponseBody()]
75+
body: typing.Annotated[typing.List[Cat], ResponseBody]
7676
count: typing.Annotated[int, Header('X-Count')]
7777

7878

0 commit comments

Comments
 (0)