Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct access to attributes #5

Closed
romanchyla opened this issue Jun 9, 2017 · 2 comments
Closed

Direct access to attributes #5

romanchyla opened this issue Jun 9, 2017 · 2 comments

Comments

@romanchyla
Copy link
Contributor

In [9]: r.bibcode = 'foo'

In [10]: r
Out[10]: <adsmsg.bibrecord.BibRecord at 0x7f9f5ed9acd0>

In [11]: str(r)
Out[11]: '<adsmsg.bibrecord.BibRecord object at 0x7f9f5ed9acd0>'

In [12]: r.__str__()
Out[12]: '<adsmsg.bibrecord.BibRecord object at 0x7f9f5ed9acd0>'

In [13]: r.bibcode
Out[13]: 'foo'

In [14]: r.serialize()
---------------------------------------------------------------------------
EncodeError                               Traceback (most recent call last)
<ipython-input-14-6d620e231470> in <module>()
----> 1 r.serialize()

/dvt/workspace2/ADSPipelineMsg/adsmsg/msg.pyc in serialize(self)
     26         Returns a serialized protocol buffer message
     27         """
---> 28         return self._data.SerializeToString()
     29 
     30     def is_valid(self):

EncodeError: Message adsmsg.BibRecord is missing required fields: bibcode,JSON_fingerprint,metadata,text

so I was expecting the following to work:

r = BibRecord()
r.bibcode = 'foo'
r.serialize()

i doesn't because Msg is storing things in r._data

Also, it would be really really useful to be able to do:

r = BibRecord(bibcode='foo') # and by extension r = BibRecord(**{'bibcode': 'foo', ....})
@marblestation
Copy link
Contributor

Protoc compiler does not generate a class but a metaclass, we cannot just inherit from it. If we want to have our own class, we need to use composition instead.

Direct access to attributes don't seem possible and initialization via kwargs is complex, because you can have an atribute that is a list of attributes that contain other types and lists. It might be doable but I'm not sure that the time investment is proportional to the benefits.

@romanchyla
Copy link
Contributor Author

romanchyla commented Jun 12, 2017 via email

marblestation added a commit that referenced this issue Jun 13, 2017
It addresses one small aspect of #5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants