Skip to content

Commit fbc0195

Browse files
committed
coalesce conv helper tests, fix typing lint
Signed-off-by: Filinto Duran <[email protected]>
1 parent 7126b2f commit fbc0195

File tree

3 files changed

+1251
-1319
lines changed

3 files changed

+1251
-1319
lines changed

dapr/clients/grpc/_conversation_helpers.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
get_args,
3232
get_origin,
3333
get_type_hints,
34+
cast,
3435
)
3536

3637
from dapr.clients.grpc.conversation import Params
@@ -152,7 +153,7 @@ def _json_primitive_type(v: Any) -> str:
152153

153154
# Handle Dict types
154155
if origin is dict or python_type is dict:
155-
schema: Dict[str, Any] = {'type': 'object'}
156+
schema = {'type': 'object'}
156157
if args and len(args) == 2:
157158
# Dict[str, ValueType] - add additionalProperties
158159
key_type, value_type = args
@@ -197,7 +198,7 @@ def _json_primitive_type(v: Any) -> str:
197198
f"{getattr(python_type, '__name__', 'Enum')} (enum with {count} values). "
198199
f"Provide a valid value. Schema compacted to avoid oversized enum listing."
199200
)
200-
schema: Dict[str, Any] = {'type': 'string', 'description': desc}
201+
schema = {'type': 'string', 'description': desc}
201202
if example_values:
202203
schema['examples'] = example_values
203204
return schema
@@ -277,16 +278,16 @@ def _json_primitive_type(v: Any) -> str:
277278
if not properties:
278279
return {'type': 'object'}
279280

280-
schema: Dict[str, Any] = {'type': 'object', 'properties': properties}
281+
schema = {'type': 'object', 'properties': properties}
281282
if required:
282283
schema['required'] = required
283284
return schema
284285

285286
# Fallback for unknown/unsupported types
286287
raise TypeError(
287288
f"Unsupported type in JSON schema conversion for field '{field_name}': {python_type}. "
288-
f"Please use supported typing annotations (e.g., str, int, float, bool, bytes, List[T], Dict[str, V], Union, Optional, Literal, Enum, dataclass, or plain classes)."
289-
f"You can report this issue for future support of this type. You can always create the json schema manually."
289+
f'Please use supported typing annotations (e.g., str, int, float, bool, bytes, List[T], Dict[str, V], Union, Optional, Literal, Enum, dataclass, or plain classes).'
290+
f'You can report this issue for future support of this type. You can always create the json schema manually.'
290291
)
291292

292293

@@ -705,6 +706,7 @@ def _default(o: Any):
705706
# Enum handling
706707
try:
707708
from enum import Enum as _Enum
709+
708710
if isinstance(o, _Enum):
709711
try:
710712
return o.value
@@ -716,7 +718,8 @@ def _default(o: Any):
716718
# dataclass handling
717719
try:
718720
if is_dataclass(o):
719-
return _asdict(o)
721+
# mypy: asdict expects a DataclassInstance; after the runtime guard, this cast is safe
722+
return _asdict(cast(Any, o))
720723
except Exception:
721724
pass
722725

@@ -824,7 +827,7 @@ def _coerce_literal(value: Any, lit_args: List[Any]) -> Any:
824827
if value in lit_args:
825828
return value
826829
# Try string-to-number coercions if literal set is homogeneous numeric
827-
try_coerced = []
830+
try_coerced: List[Any] = []
828831
for target in lit_args:
829832
try:
830833
if isinstance(target, int) and not isinstance(target, bool) and isinstance(value, str):

0 commit comments

Comments
 (0)