Skip to content

Commit d3877f7

Browse files
committed
Add support for .
1 parent 36b0a7d commit d3877f7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tools/tensorflow_docs/api_generator/public_api.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
from google.protobuf.message import Message as ProtoMessage
3333

34+
try:
35+
import proto
36+
except ImportError:
37+
proto = None
38+
39+
3440
_TYPING_IDS = frozenset(
3541
id(obj)
3642
for obj in typing.__dict__.values()
@@ -415,9 +421,18 @@ def add_proto_fields(path: Sequence[str], parent: Any,
415421
`children` with proto fields added as properties.
416422
"""
417423
del path
418-
if not inspect.isclass(parent) or not issubclass(parent, ProtoMessage):
424+
if not inspect.isclass(parent):
419425
return children
420426

427+
real_parent = parent
428+
if not issubclass(parent, ProtoMessage):
429+
if proto is not None:
430+
if issubclass(parent, proto.message.Message):
431+
parent = parent.pb()
432+
children = [(name, value) for (name, value) in children if name != "meta"]
433+
else:
434+
return children
435+
421436
descriptor = getattr(parent, 'DESCRIPTOR', None)
422437
if descriptor is None:
423438
return children
@@ -465,7 +480,7 @@ def add_proto_fields(path: Sequence[str], parent: Any,
465480
field_properties[name] = prop
466481

467482
for name, prop in field_properties.items():
468-
setattr(parent, name, prop)
483+
setattr(real_parent, name, prop)
469484

470485
children = dict(children)
471486
children.update(field_properties)

0 commit comments

Comments
 (0)