@@ -17,7 +17,7 @@ This template generates basic Python Dataclasses from Proto Messages.
1717// A proto file for the Widget service
1818syntax = "proto3";
1919
20- package simple_types.v1.widget ;
20+ package simple_types.v1 ;
2121
2222// The Widget type defines a Widget object
2323message Widget {
@@ -31,19 +31,31 @@ message Widget {
3131 repeated string colors = 4;
3232 // global stock by color
3333 map<string, int32> stock_by_color = 5;
34+ // The number of widgets in stock at various locations
35+ map<int32, WidgetFactory> stock_by_warehouse = 6;
3436
3537 // The Size enum defines the size of the widget
3638 enum Size {
3739 // The Widget Size is unknown
38- UNKNOWN = 0;
40+ SIZE_UNSPECIFIED = 0;
3941 // The Widget Size is small
40- SMALL = 1;
42+ SIZE_SMALL = 1;
4143 // The Widget Size is medium
42- MEDIUM = 2;
44+ SIZE_MEDIUM = 2;
4345 // The Widget Size is large
44- LARGE = 3;
46+ SIZE_LARGE = 3;
4547 }
4648}
49+
50+ // Describes a Widget Factory
51+ message WidgetFactory {
52+ // The id of the factory
53+ int32 id = 1 ;
54+ // The name of the factory
55+ string name = 2 ;
56+ // The address of the factory
57+ string address = 3 ;
58+ }
4759```
4860</details >
4961
@@ -65,34 +77,63 @@ class Widget:
6577 r """ The Widget type defines a Widget object"""
6678
6779 # The fixed set of attrbiutes for the Widget Type.
68- __slots__ = (" name" , " size" , " created" , " colors" , " stock_by_color" )
69-
70- # The name of the widget
71- name: " str"
72-
73- # The size of the widget
80+ __slots__ = (
81+ " name" ,
82+ " size" ,
83+ " created" ,
84+ " colors" ,
85+ " stock_by_color" ,
86+ " stock_by_warehouse" ,
87+ )
88+
89+ # The name of the widget.
90+ name: str
91+
92+ # The size of the widget.
7493 size: " Size"
7594
76- # The date the widget was created
77- created: " int"
95+ # The date the widget was created.
96+ created: int
97+
98+ # The colors available for the widget.
99+ colors: Tuple[str ] = dataclasses.field(default_factory = Tuple)
78100
79- # The colors available for the widget
80- colors: " Tuple [str] " = dataclasses.field(default_factory = Tuple)
101+ # global stock by color.
102+ stock_by_color: OrderedDict [str , int ] = dataclasses.field(default_factory = Tuple)
81103
82- # global stock by color
83- stock_by_color: " OrderedDict[str, int]" = dataclasses.field(default_factory = Tuple)
104+ # The number of widgets in stock at various locations.
105+ stock_by_warehouse: OrderedDict[int , " WidgetFactory" ] = dataclasses.field(
106+ default_factory = Tuple
107+ )
84108
85109 class Size (Enum ):
86110 r """ The Size enum defines the size of the widget"""
87111
88112 # The Widget Size is unknown
89- UNKNOWN = 0
113+ SIZE_UNSPECIFIED = 0
90114 # The Widget Size is small
91- SMALL = 1
115+ SIZE_SMALL = 1
92116 # The Widget Size is medium
93- MEDIUM = 2
117+ SIZE_MEDIUM = 2
94118 # The Widget Size is large
95- LARGE = 3
119+ SIZE_LARGE = 3
120+
121+
122+ @dataclasses.dataclasses
123+ class WidgetFactory :
124+ r """ Describes a Widget Factory"""
125+
126+ # The fixed set of attrbiutes for the WidgetFactory Type.
127+ __slots__ = (" id" , " name" , " address" )
128+
129+ # The id of the factory.
130+ id : int
131+
132+ # The name of the factory.
133+ name: str
134+
135+ # The address of the factory.
136+ address: str
96137
97138```
98139</details >
0 commit comments