Skip to content

parser: ensure prefix is separated when traversing #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/betterproto/plugin/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def _traverse(
for i, item in enumerate(items):
# Adjust the name since we flatten the hierarchy.
# Todo: don't change the name, but include full name in returned tuple
item.name = next_prefix = prefix + item.name
item.name = next_prefix = f"{prefix}_{item.name}"
yield item, path + [i]

if isinstance(item, DescriptorProto):
for enum in item.enum_type:
enum.name = next_prefix + enum.name
enum.name = f"{next_prefix}_{enum.name}"
yield enum, path + [i, 4]

if item.nested_type:
Expand Down
11 changes: 11 additions & 0 deletions tests/inputs/casing_inner_class/casing_inner_class.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// https://github.com/danielgtaylor/python-betterproto/issues/344
syntax = "proto3";

package casing_inner_class;

message Test {
message inner_class {
sint32 old_exp = 1;
}
inner_class inner = 2;
}
14 changes: 14 additions & 0 deletions tests/inputs/casing_inner_class/test_casing_inner_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import tests.output_betterproto.casing_inner_class as casing_inner_class


def test_message_casing_inner_class_name():
assert hasattr(
casing_inner_class, "TestInnerClass"
), "Inline defined Message is correctly converted to CamelCase"


def test_message_casing_inner_class_attributes():
message = casing_inner_class.Test()
assert hasattr(
message.inner, "old_exp"
), "Inline defined Message attribute is snake_case"