Skip to content

Commit 63bd5b1

Browse files
author
Luke Sneeringer
authored
[feat] Improve enums. (#127)
This uses proto-plus enums, which add enum support to the marshal and cause enums (rather than ints) to be returned, and add support for accepting strings.
1 parent b6637ce commit 63bd5b1

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

packages/gapic-generator/gapic/templates/$namespace/$name_$version/$sub/types/$proto.py.j2

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{% extends "_base.py.j2" %}
22

33
{% block content -%}
4-
{% with e = proto.disambiguate('enum'), p = proto.disambiguate('proto') %}
5-
{% if proto.all_enums|length -%}
6-
import enum{% if e != 'enum' %} as {{ e }}{% endif %}
7-
8-
{% endif -%}
9-
{% if proto.messages|length -%}
4+
{% with p = proto.disambiguate('proto') %}
5+
{% if proto.messages|length or proto.all_enums|length -%}
106
import proto{% if p != 'proto' %} as {{ p }}{% endif -%}
117
{% endif %}
128

packages/gapic-generator/gapic/templates/$namespace/$name_$version/$sub/types/_enum.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class {{ enum.name }}({{ e }}.IntEnum):
1+
class {{ enum.name }}({{ p }}.Enum):
22
r"""{{ enum.meta.doc|rst(indent=4) }}"""
33
{% for enum_value in enum.values -%}
44
{{ enum_value.name }} = {{ enum_value.number }}

packages/gapic-generator/gapic/templates/setup.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ setuptools.setup(
2222
'google-api-core >= 1.8.0, < 2.0.0dev',
2323
'googleapis-common-protos >= 1.5.8',
2424
'grpcio >= 1.10.0',
25-
'proto-plus >= 0.3.0',
25+
'proto-plus >= 0.4.0',
2626
),
2727
classifiers=[
2828
'Development Status :: 3 - Alpha',

0 commit comments

Comments
 (0)