This repository was archived by the owner on Jun 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
src/betterproto2_compiler Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change
1
+ import typing
2
+
1
3
import betterproto2
2
4
3
5
from betterproto2_compiler .lib .google .protobuf import Any as VanillaAny
@@ -31,6 +33,14 @@ def unpack(self, message_pool: "betterproto2.MessagePool | None" = None) -> bett
31
33
32
34
return message_type ().parse (self .value )
33
35
34
- def to_dict (self ) -> dict : # pyright: ignore [reportIncompatibleMethodOverride]
35
- # TOOO improve when dict is updated
36
- return {"@type" : self .type_url , "value" : self .unpack ().to_dict ()}
36
+ def to_dict (self , ** kwargs ) -> dict [str , typing .Any ]:
37
+ output : dict [str , typing .Any ] = {"@type" : self .type_url }
38
+
39
+ value = self .unpack ()
40
+
41
+ if type (value ).to_dict == betterproto2 .Message .to_dict :
42
+ output .update (value .to_dict (** kwargs ))
43
+ else :
44
+ output ["value" ] = value .to_dict (** kwargs )
45
+
46
+ return output
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import builtins
22
22
import datetime
23
23
import warnings
24
24
from collections.abc import AsyncIterable, AsyncIterator, Iterable
25
+ import typing
25
26
from typing import TYPE_CHECKING
26
27
27
28
{% if output_file .settings .pydantic_dataclasses %}
You can’t perform that action at this time.
0 commit comments