Skip to content

Commit

Permalink
Simplify code: delete py_input_message (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienVannson authored Sep 17, 2024
1 parent 8fdcb38 commit 8d25c96
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
24 changes: 0 additions & 24 deletions src/betterproto/plugin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,30 +755,6 @@ def route(self) -> str:
)
return f"/{package_part}{self.parent.proto_name}/{self.proto_name}"

@property
def py_input_message(self) -> Optional[MessageCompiler]:
"""Find the input message object.
Returns
-------
Optional[MessageCompiler]
Method instance representing the input message.
If not input message could be found or there are no
input messages, None is returned.
"""
package, name = parse_source_type_name(self.proto_obj.input_type)

# Nested types are currently flattened without dots.
# Todo: keep a fully quantified name in types, that is
# comparable with method.input_type
for msg in self.request.all_messages:
if (
msg.py_name == pythonize_class_name(name.replace(".", ""))
and msg.output_file.package == package
):
return msg
return None

@property
def py_input_message_type(self) -> str:
"""String representation of the Python type corresponding to the
Expand Down
4 changes: 2 additions & 2 deletions src/betterproto/templates/template.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
{% for method in service.methods %}
async def {{ method.py_name }}(self
{%- if not method.client_streaming -%}
{%- if method.py_input_message -%}, {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"{%- endif -%}
, {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"
{%- else -%}
{# Client streaming: need a request iterator instead #}
, {{ method.py_input_message_param }}_iterator: {{ output_file.typing_compiler.union(output_file.typing_compiler.async_iterable(method.py_input_message_type), output_file.typing_compiler.iterable(method.py_input_message_type)) }}
Expand Down Expand Up @@ -153,7 +153,7 @@ class {{ service.py_name }}Base(ServiceBase):
{% for method in service.methods %}
async def {{ method.py_name }}(self
{%- if not method.client_streaming -%}
{%- if method.py_input_message -%}, {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"{%- endif -%}
, {{ method.py_input_message_param }}: "{{ method.py_input_message_type }}"
{%- else -%}
{# Client streaming: need a request iterator instead #}
, {{ method.py_input_message_param }}_iterator: {{ output_file.typing_compiler.async_iterator(method.py_input_message_type) }}
Expand Down

0 comments on commit 8d25c96

Please sign in to comment.