MCPcopy Index your code
hub / github.com/danielgtaylor/python-betterproto / _traverse

Function _traverse

src/betterproto/plugin/parser.py:54–70  ·  view source on GitHub ↗
(
        path: List[int],
        items: Union[List[EnumDescriptorProto], List[DescriptorProto]],
        prefix: str = "",
    )

Source from the content-addressed store, hash-verified

52]:
53 # Todo: Keep information about nested hierarchy
54 def _traverse(
55 path: List[int],
56 items: Union[List[EnumDescriptorProto], List[DescriptorProto]],
57 prefix: str = "",
58 ) -> Generator[
59 Tuple[Union[EnumDescriptorProto, DescriptorProto], List[int]], None, None
60 ]:
61 for i, item in enumerate(items):
62 # Adjust the name since we flatten the hierarchy.
63 # Todo: don't change the name, but include full name in returned tuple
64 item.name = next_prefix = f"{prefix}_{item.name}"
65 yield item, [*path, i]
66
67 if isinstance(item, DescriptorProto):
68 # Get nested types.
69 yield from _traverse([*path, i, 4], item.enum_type, next_prefix)
70 yield from _traverse([*path, i, 3], item.nested_type, next_prefix)
71
72 yield from _traverse([5], proto_file.enum_type)
73 yield from _traverse([4], proto_file.message_type)

Callers 1

traverseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected