-
Notifications
You must be signed in to change notification settings - Fork 428
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
Add the ability for pynamo to read + write map and list attributes #146
Conversation
SHORT_ATTR_TYPES = [STRING_SHORT, STRING_SET_SHORT, NUMBER_SHORT, NUMBER_SET_SHORT, BINARY_SHORT, BINARY_SET_SHORT] | ||
MAP = 'Map' | ||
LIST = 'List' | ||
SHORT_ATTR_TYPES = [STRING_SHORT, STRING_SET_SHORT, NUMBER_SHORT, NUMBER_SET_SHORT, BINARY_SHORT, BINARY_SET_SHORT, MAP_SHORT] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIST_SHORT missing here
""" | ||
rval = [] | ||
for v in values: | ||
if v is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sensing a pattern with all of these.. surely we can write this in a generic way such that we don't need to do the type checks every time?
@@ -257,3 +258,181 @@ def deserialize(self, value): | |||
Takes a UTC datetime string and returns a datetime object | |||
""" | |||
return parse(value, dayfirst=False).datetime | |||
|
|||
|
|||
class MapAttribute(Attribute): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so when I want to define an MapAttribute that requires verification, I need to create a subclass, otherwise I can use MapAttribute directly, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bingo. for our user case we would just want to do
class CouponTemplate(MapAttribute):
code = UnicodeAttribute()
...
Changes Unknown when pulling da0246a on jmphilli:nested-validation into * on jlafon:devel*. |
return all(self.is_type_safe(k, v) for k, v in six.iteritems(self._get_attributes())) | ||
|
||
def serialize(self, values): | ||
rval = dict() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consistency use literal {}
LGTM! |
… conditional_operator
2 similar comments
Merged into |
Context
This allows pynamo to serialize + deserialize map and list types.