parser: ensure prefix is separated when traversing (#353)
This commit is contained in:
parent
69f4192341
commit
62da35b3ea
@ -44,12 +44,12 @@ def traverse(
|
|||||||
for i, item in enumerate(items):
|
for i, item in enumerate(items):
|
||||||
# Adjust the name since we flatten the hierarchy.
|
# Adjust the name since we flatten the hierarchy.
|
||||||
# Todo: don't change the name, but include full name in returned tuple
|
# 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]
|
yield item, path + [i]
|
||||||
|
|
||||||
if isinstance(item, DescriptorProto):
|
if isinstance(item, DescriptorProto):
|
||||||
for enum in item.enum_type:
|
for enum in item.enum_type:
|
||||||
enum.name = next_prefix + enum.name
|
enum.name = f"{next_prefix}_{enum.name}"
|
||||||
yield enum, path + [i, 4]
|
yield enum, path + [i, 4]
|
||||||
|
|
||||||
if item.nested_type:
|
if item.nested_type:
|
||||||
|
11
tests/inputs/casing_inner_class/casing_inner_class.proto
Normal file
11
tests/inputs/casing_inner_class/casing_inner_class.proto
Normal file
@ -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
tests/inputs/casing_inner_class/test_casing_inner_class.py
Normal file
14
tests/inputs/casing_inner_class/test_casing_inner_class.py
Normal file
@ -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"
|
Loading…
x
Reference in New Issue
Block a user