@@ -79,59 +79,29 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
79
79
{% for method in service .methods %}
80
80
async def {{ method.py_name }}(self
81
81
{% - if not method .client_streaming -%}
82
- {% - if method .py_input_message and method .py_input_message .fields -%} , *,
83
- {% - for field in method .py_input_message .fields -%}
84
- {{ field.py_name }}: {% if field .py_name in method .mutable_default_args and not field .annotation .startswith ("Optional[" ) -%}
85
- Optional[{{ field.annotation }}]
86
- {% - else -%}
87
- {{ field.annotation }}
88
- {% - endif -%} =
89
- {% - if field .py_name not in method .mutable_default_args -%}
90
- {{ field.default_value_string }}
91
- {% - else -%}
92
- None
93
- {% endif -%}
94
- {% - if not loop .last %} , {% endif -%}
95
- {% - endfor -%}
96
- {% - endif -%}
82
+ {% - if method .py_input_message -%} , {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"{% - endif -%}
97
83
{% - else -%}
98
84
{# Client streaming: need a request iterator instead #}
99
- , request_iterator : Union[AsyncIterable["{{ method.py_input_message_type }}"], Iterable["{{ method.py_input_message_type }}"]]
85
+ , {{ method.py_input_message_param }}_iterator : Union[AsyncIterable["{{ method.py_input_message_type }}"], Iterable["{{ method.py_input_message_type }}"]]
100
86
{% - endif -%}
101
87
) -> {% if method .server_streaming %} AsyncIterator["{{ method.py_output_message_type }}"]{% else %} "{{ method.py_output_message_type }}"{% endif %} :
102
88
{% if method .comment %}
103
89
{{ method.comment }}
104
90
105
91
{% endif %}
106
- {% - for py_name , zero in method .mutable_default_args .items () %}
107
- {{ py_name }} = {{ py_name }} or {{ zero }}
108
- {% endfor %}
109
-
110
- {% if not method .client_streaming %}
111
- request = {{ method.py_input_message_type }}()
112
- {% for field in method .py_input_message .fields %}
113
- {% if field .field_type == 'message' %}
114
- if {{ field.py_name }} is not None:
115
- request.{{ field.py_name }} = {{ field.py_name }}
116
- {% else %}
117
- request.{{ field.py_name }} = {{ field.py_name }}
118
- {% endif %}
119
- {% endfor %}
120
- {% endif %}
121
-
122
92
{% if method .server_streaming %}
123
93
{% if method .client_streaming %}
124
94
async for response in self._stream_stream(
125
95
"{{ method.route }}",
126
- request_iterator ,
96
+ {{ method.py_input_message_param }}_iterator ,
127
97
{{ method.py_input_message_type }},
128
98
{{ method.py_output_message_type.strip('"') }},
129
99
):
130
100
yield response
131
101
{% else %} {# i.e. not client streaming #}
132
102
async for response in self._unary_stream(
133
103
"{{ method.route }}",
134
- request ,
104
+ {{ method.py_input_message_param }} ,
135
105
{{ method.py_output_message_type.strip('"') }},
136
106
):
137
107
yield response
@@ -141,14 +111,14 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
141
111
{% if method .client_streaming %}
142
112
return await self._stream_unary(
143
113
"{{ method.route }}",
144
- request_iterator ,
114
+ {{ method.py_input_message_param }}_iterator ,
145
115
{{ method.py_input_message_type }},
146
116
{{ method.py_output_message_type.strip('"') }}
147
117
)
148
118
{% else %} {# i.e. not client streaming #}
149
119
return await self._unary_unary(
150
120
"{{ method.route }}",
151
- request ,
121
+ {{ method.py_input_message_param }} ,
152
122
{{ method.py_output_message_type.strip('"') }}
153
123
)
154
124
{% endif %} {# client streaming #}
@@ -167,19 +137,10 @@ class {{ service.py_name }}Base(ServiceBase):
167
137
{% for method in service .methods %}
168
138
async def {{ method.py_name }}(self
169
139
{% - if not method .client_streaming -%}
170
- {% - if method .py_input_message and method .py_input_message .fields -%} ,
171
- {% - for field in method .py_input_message .fields -%}
172
- {{ field.py_name }}: {% if field .py_name in method .mutable_default_args and not field .annotation .startswith ("Optional[" ) -%}
173
- Optional[{{ field.annotation }}]
174
- {% - else -%}
175
- {{ field.annotation }}
176
- {% - endif -%}
177
- {% - if not loop .last %} , {% endif -%}
178
- {% - endfor -%}
179
- {% - endif -%}
140
+ {% - if method .py_input_message -%} , {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"{% - endif -%}
180
141
{% - else -%}
181
142
{# Client streaming: need a request iterator instead #}
182
- , request_iterator : AsyncIterator["{{ method.py_input_message_type }}"]
143
+ , {{ method.py_input_message_param }}_iterator : AsyncIterator["{{ method.py_input_message_type }}"]
183
144
{% - endif -%}
184
145
) -> {% if method .server_streaming %} AsyncIterator["{{ method.py_output_message_type }}"]{% else %} "{{ method.py_output_message_type }}"{% endif %} :
185
146
{% if method .comment %}
@@ -194,25 +155,17 @@ class {{ service.py_name }}Base(ServiceBase):
194
155
async def __rpc_{{ method.py_name }}(self, stream: grpclib.server.Stream) -> None:
195
156
{% if not method .client_streaming %}
196
157
request = await stream.recv_message()
197
-
198
- request_kwargs = {
199
- {% for field in method .py_input_message .fields %}
200
- "{{ field.py_name }}": request.{{ field.py_name }},
201
- {% endfor %}
202
- }
203
-
204
158
{% else %}
205
- request_kwargs = {"request_iterator": stream.__aiter__()}
159
+ request = stream.__aiter__()
206
160
{% endif %}
207
-
208
161
{% if not method .server_streaming %}
209
- response = await self.{{ method.py_name }}(**request_kwargs )
162
+ response = await self.{{ method.py_name }}(request )
210
163
await stream.send_message(response)
211
164
{% else %}
212
165
await self._call_rpc_handler_server_stream(
213
166
self.{{ method.py_name }},
214
167
stream,
215
- request_kwargs ,
168
+ request ,
216
169
)
217
170
{% endif %}
218
171
0 commit comments