Skip to content

Commit

Permalink
Merge pull request #5 from deleted/messagemeta
Browse files Browse the repository at this point in the history
Accept MessageMeta as an additional metaclass for generated types
  • Loading branch information
Ed-XCF authored Jan 24, 2023
2 parents af355a3 + cae39a0 commit efb7812
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion protobuf2pydantic/biz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
from google.protobuf.reflection import GeneratedProtocolMessageType
from google.protobuf.descriptor import Descriptor, FieldDescriptor, EnumDescriptor

message_metaclasses = [GeneratedProtocolMessageType]
try:
from google._upb._message import MessageMeta

message_metaclasses.append(MessageMeta)
except ImportError:
pass

tab = " " * 4
one_line, two_lines = linesep * 2, linesep * 3
type_mapping = {
Expand Down Expand Up @@ -99,7 +107,7 @@ def pb2_to_pydantic(module) -> str:
pydantic_models: List[str] = []
for i in dir(module):
obj = getattr(module, i)
if not isinstance(obj, GeneratedProtocolMessageType):
if not any(isinstance(obj, metacls) for metacls in message_metaclasses):
continue
model_string = msg2pydantic(0, obj.DESCRIPTOR)
pydantic_models.append(model_string)
Expand Down

0 comments on commit efb7812

Please sign in to comment.