Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit aa56afa

Browse files
committed
Redefine method definition for sync stubs
1 parent 1b47d57 commit aa56afa

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

src/betterproto2_compiler/templates/service_stub.py.j2

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,7 @@ class {% block class_name %}{% endblock %}({% block inherit_from %}{% endblock %
1010
{% block class_content %}{% endblock %}
1111

1212
{% for method in service.methods %}
13-
async def {{ method.py_name }}(self
14-
{%- if not method.client_streaming -%}
15-
, message:
16-
{%- if method.is_input_msg_empty -%}
17-
"{{ method.py_input_message_type }} | None" = None
18-
{%- else -%}
19-
"{{ method.py_input_message_type }}"
20-
{%- endif -%}
21-
{%- else -%}
22-
{# Client streaming: need a request iterator instead #}
23-
, messages: "AsyncIterable[{{ method.py_input_message_type }}] | Iterable[{{ method.py_input_message_type }}]"
24-
{%- endif -%}
25-
,
26-
*
27-
, timeout: "float | None" = None
28-
, deadline: "Deadline | None" = None
29-
, metadata: "MetadataLike | None" = None
30-
) -> "{% if method.server_streaming %}AsyncIterator[{{ method.py_output_message_type }}]{% else %}{{ method.py_output_message_type }}{% endif %}":
13+
{% block method_definition scoped required %}{% endblock %}
3114
{% if method.comment %}
3215
"""
3316
{{ method.comment | indent(8) }}

src/betterproto2_compiler/templates/service_stub_async.py.j2

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,25 @@
33
{# Class definition #}
44
{% block class_name %}{{ service.py_name }}Stub{% endblock %}
55
{% block inherit_from %}betterproto2.ServiceStub{% endblock %}
6+
7+
{# Methods definition #}
8+
{% block method_definition %}
9+
async def {{ method.py_name }}(self
10+
{%- if not method.client_streaming -%}
11+
, message:
12+
{%- if method.is_input_msg_empty -%}
13+
"{{ method.py_input_message_type }} | None" = None
14+
{%- else -%}
15+
"{{ method.py_input_message_type }}"
16+
{%- endif -%}
17+
{%- else -%}
18+
{# Client streaming: need a request iterator instead #}
19+
, messages: "AsyncIterable[{{ method.py_input_message_type }}] | Iterable[{{ method.py_input_message_type }}]"
20+
{%- endif -%}
21+
,
22+
*
23+
, timeout: "float | None" = None
24+
, deadline: "Deadline | None" = None
25+
, metadata: "MetadataLike | None" = None
26+
) -> "{% if method.server_streaming %}AsyncIterator[{{ method.py_output_message_type }}]{% else %}{{ method.py_output_message_type }}{% endif %}":
27+
{% endblock %}

src/betterproto2_compiler/templates/service_stub_sync.py.j2

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,25 @@
88
def __init__(self, channel: grpc.Channel):
99
self._channel = channel
1010
{% endblock %}
11+
12+
{# Methods definition #}
13+
{% block method_definition %}
14+
def {{ method.py_name }}(self
15+
{%- if not method.client_streaming -%}
16+
, message:
17+
{%- if method.is_input_msg_empty -%}
18+
"{{ method.py_input_message_type }} | None" = None
19+
{%- else -%}
20+
"{{ method.py_input_message_type }}"
21+
{%- endif -%}
22+
{%- else -%}
23+
{# Client streaming: need a request iterator instead #}
24+
, messages: "Iterable[{{ method.py_input_message_type }}]"
25+
{%- endif -%}
26+
,
27+
*
28+
, timeout: "float | None" = None
29+
, deadline: "Deadline | None" = None
30+
, metadata: "MetadataLike | None" = None
31+
) -> "{% if method.server_streaming %}Iterator[{{ method.py_output_message_type }}]{% else %}{{ method.py_output_message_type }}{% endif %}":
32+
{% endblock %}

0 commit comments

Comments
 (0)