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

Commit 1b47d57

Browse files
committed
Sync stub: add constructor, remove parent class
1 parent 52ab890 commit 1b47d57

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/betterproto2_compiler/templates/header.py.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ from dataclasses import dataclass
3535
import betterproto2
3636
{% if output_file.services %}
3737
from betterproto2.grpc.grpclib_server import ServiceBase
38+
import grpc
3839
import grpclib
3940
{% endif %}
4041

src/betterproto2_compiler/templates/service_stub.py.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class {% block class_name %}{% endblock %}(betterproto2.ServiceStub):
1+
class {% block class_name %}{% endblock %}({% block inherit_from %}{% endblock %}):
22
{% if service.comment %}
33
"""
44
{{ service.comment | indent(4) }}
@@ -7,6 +7,8 @@ class {% block class_name %}{% endblock %}(betterproto2.ServiceStub):
77
pass
88
{% endif %}
99

10+
{% block class_content %}{% endblock %}
11+
1012
{% for method in service.methods %}
1113
async def {{ method.py_name }}(self
1214
{%- if not method.client_streaming -%}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{% extends "service_stub.py.j2" %}
22

3+
{# Class definition #}
34
{% block class_name %}{{ service.py_name }}Stub{% endblock %}
5+
{% block inherit_from %}betterproto2.ServiceStub{% endblock %}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{% extends "service_stub.py.j2" %}
22

3+
{# Class definition #}
34
{% block class_name %}{{ service.py_name }}SyncStub{% endblock %}
5+
6+
{% block class_content %}
7+
{# TODO move to parent class #}
8+
def __init__(self, channel: grpc.Channel):
9+
self._channel = channel
10+
{% endblock %}

0 commit comments

Comments
 (0)