@@ -79,59 +79,29 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
7979 {% for method in service .methods %}
8080 async def {{ method.py_name }}(self
8181 {% - 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 -%}
9783 {% - else -%}
9884 {# 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 }}"]]
10086 {% - endif -%}
10187 ) -> {% if method .server_streaming %} AsyncIterator["{{ method.py_output_message_type }}"]{% else %} "{{ method.py_output_message_type }}"{% endif %} :
10288 {% if method .comment %}
10389{{ method.comment }}
10490
10591 {% 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-
12292 {% if method .server_streaming %}
12393 {% if method .client_streaming %}
12494 async for response in self._stream_stream(
12595 "{{ method.route }}",
126- request_iterator ,
96+ {{ method.py_input_message_param }}_iterator ,
12797 {{ method.py_input_message_type }},
12898 {{ method.py_output_message_type.strip('"') }},
12999 ):
130100 yield response
131101 {% else %} {# i.e. not client streaming #}
132102 async for response in self._unary_stream(
133103 "{{ method.route }}",
134- request ,
104+ {{ method.py_input_message_param }} ,
135105 {{ method.py_output_message_type.strip('"') }},
136106 ):
137107 yield response
@@ -141,14 +111,14 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
141111 {% if method .client_streaming %}
142112 return await self._stream_unary(
143113 "{{ method.route }}",
144- request_iterator ,
114+ {{ method.py_input_message_param }}_iterator ,
145115 {{ method.py_input_message_type }},
146116 {{ method.py_output_message_type.strip('"') }}
147117 )
148118 {% else %} {# i.e. not client streaming #}
149119 return await self._unary_unary(
150120 "{{ method.route }}",
151- request ,
121+ {{ method.py_input_message_param }} ,
152122 {{ method.py_output_message_type.strip('"') }}
153123 )
154124 {% endif %} {# client streaming #}
@@ -167,19 +137,10 @@ class {{ service.py_name }}Base(ServiceBase):
167137 {% for method in service .methods %}
168138 async def {{ method.py_name }}(self
169139 {% - 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 -%}
180141 {% - else -%}
181142 {# 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 }}"]
183144 {% - endif -%}
184145 ) -> {% if method .server_streaming %} AsyncIterator["{{ method.py_output_message_type }}"]{% else %} "{{ method.py_output_message_type }}"{% endif %} :
185146 {% if method .comment %}
@@ -194,25 +155,17 @@ class {{ service.py_name }}Base(ServiceBase):
194155 async def __rpc_{{ method.py_name }}(self, stream: grpclib.server.Stream) -> None:
195156 {% if not method .client_streaming %}
196157 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-
204158 {% else %}
205- request_kwargs = {"request_iterator": stream.__aiter__()}
159+ request = stream.__aiter__()
206160 {% endif %}
207-
208161 {% if not method .server_streaming %}
209- response = await self.{{ method.py_name }}(**request_kwargs )
162+ response = await self.{{ method.py_name }}(request )
210163 await stream.send_message(response)
211164 {% else %}
212165 await self._call_rpc_handler_server_stream(
213166 self.{{ method.py_name }},
214167 stream,
215- request_kwargs ,
168+ request ,
216169 )
217170 {% endif %}
218171
0 commit comments