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

@property attributes are missing in serialized output #21

Open
GeorgeLubaretsi opened this issue Sep 13, 2018 · 1 comment
Open

@property attributes are missing in serialized output #21

GeorgeLubaretsi opened this issue Sep 13, 2018 · 1 comment

Comments

@GeorgeLubaretsi
Copy link

Example:

import related

@related.immutable
class Person(object):
    first_name = related.StringField()
    last_name = related.StringField()

    @property
    def full_name(self):
        return '{0} {1}'.format(self.first_name, self.last_name)


person = Person(first_name='John', last_name='Doe')

print(related.to_dict(person))
# OrderedDict([('first_name', 'John'), ('last_name', 'Doe')])

I think property attributes should be included in a serialized output. Perhaps iterating over the attributes and getting all the values of property instances should be the easiest approach?

@imaurer
Copy link
Contributor

imaurer commented Oct 13, 2018

Interesting idea. But automatically putting all properties into the JSON format will probably have some unintended consequences. It might be better if there was something like this:

    @related.property
    def full_name(self):
        return '{0} {1}'.format(self.first_name, self.last_name)

thoughts?

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