This has also been implemented internally and will be included in the next release.
On Tue, Sep 11, 2012 at 6:07 AM, Jan Koriťák <[email protected]> wrote: > Hello, > > We would like to use Custom options for message fields in Python. > > According to > https://developers.google.com/protocol-buffers/docs/proto?hl=cs : > "As of this writing (version 2.0.3), custom options are not accessible in > Python." > > I would like to ask if there was any progress since then or can it be > expected in near future ? > > I have actually tried to use the custom options, and I could only get it > working after hacking the generated Python file by moving the line with > call to "RegisterExtension" right after definition of the Extension field. > So maybe we just need to tweak protoc a bit. > > My test proto: > import "google/protobuf/descriptor.proto"; > > extend google.protobuf.FieldOptions { > optional string comment = 50002; > } > > message MyMessage { > optional string foo = 1 [(comment) = "Not particularly useful field"]; > } > > Python console: > In [1]: import test_pb2 > > In [2]: > test_pb2.MyMessage.DESCRIPTOR.fields[0].GetOptions().Extensions[test_pb2.comment] > Out[2]: u'' > > Hacked test_pb2.py: > ... > COMMENT_FIELD_NUMBER = 50002 > comment = descriptor.FieldDescriptor( > name='comment', full_name='comment', index=0, > number=50002, type=9, cpp_type=9, label=1, > has_default_value=False, default_value=unicode("", "utf-8"), > message_type=None, enum_type=None, containing_type=None, > is_extension=True, extension_scope=None, > options=None) > > # MOVED FROM THE END OF FILE > google.protobuf.descriptor_pb2.FieldOptions.RegisterExtension(comment) > ... > > Python console: > > In [1]: import test_pb2 > > In [2]: > test_pb2.MyMessage.DESCRIPTOR.fields[0].GetOptions().Extensions[test_pb2.comment] > Out[2]: u'Not particularly useful field' > > Best regards, > Jan Koriťák > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/protobuf/-/b4pQsNMoEzYJ. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
