-
Notifications
You must be signed in to change notification settings - Fork 20
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
[improvement] add support for hashing / settype + more tests #39
[improvement] add support for hashing / settype + more tests #39
Conversation
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.
Although this change is not a break, adopting this change in conjure-python would be since we're changing the request/response types for sets. I think long term this is the right thing to do, but i'm unsure if it is the right time to have cause a major rev. @ahggns for thoughts
decoded_A2 = ConjureDecoder().read_from_string("\"A\"", TestEnum) | ||
assert decoded_A != decoded_B | ||
assert decoded_A == decoded_A2 | ||
|
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: white space
B = 2 | ||
C = 3 | ||
|
||
def test_enum_decode(): |
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.
could we also add some negative test cases?
from conjure_python_client import ConjureDecoder, ConjureEnumType | ||
|
||
|
||
class TestEnum(ConjureEnumType): |
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.
could we use a generated enum instead of a hand rolled one?
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.
done
conjure_python_client/_lib/types.py
Outdated
@@ -36,6 +37,14 @@ def __init__(self, item_type): | |||
self.item_type = item_type | |||
|
|||
|
|||
class SetType(ConjureType): | |||
item_type = None # type: Type[DecodableType] |
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.
could we also define __slots__
for the class to reduce memory overhead?
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.
Could be done in a follow up along with the other type classes
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.
seems like premature optimization to me
@@ -62,6 +63,8 @@ def check_null_field( | |||
cls, obj, deserialized, python_arg_name, field_definition): | |||
if isinstance(field_definition.field_type, ListType): | |||
deserialized[python_arg_name] = [] | |||
elif isinstance(field_definition.field_type, SetType): | |||
deserialized[python_arg_name] = [] |
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.
should this not be a frozenset?
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 dont think so?
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.
it should. otherwise the actual type of a set member in an object will vary depending on the wire format of the response.
- The type will be
frozenset
if the collection is present ex:{ "foo":[1,2] }
- The type will be
array
if the collection is absent. ex:{}
,{ "foo": null }
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.
oh misunderstood which thing you were suggesting swapping to frozen set. you are correct
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.
fixed and added a test
|
||
def test_set_does_not_decode_from_json_null(): | ||
with pytest.raises(Exception): | ||
ConjureDecoder().read_from_string("null", SetType(int)) |
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.
is this a json null or the string null?
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.
json null
import pytest | ||
from conjure_python_client import ConjureDecoder, ListType, ConjureUnionType, ConjureFieldDefinition | ||
|
||
class TestUnion(ConjureUnionType): |
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.
same here, use a generated union instead of a hand rolled one
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.
In agreement that this is directionally correct, and the use of proper set types is unlikely to break existing code which was mostly treating lists as sets anyway.
As far as breaks go I think we have a handful of other breaks we'd been considering and it'd probably be better to do a bunch at once so we can be more watchful of the rollout.
test/serde/test_decode_union.py
Outdated
assert not decoded_C.c | ||
|
||
def test_invalid_decode(): | ||
with pytest.raises(Exception): |
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.
Is there a more specific error we can expect?
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.
nope. the code just throws Exception at the moment
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.
this code is copied from existing tests
conjure_python_client/_lib/types.py
Outdated
@@ -36,6 +37,14 @@ def __init__(self, item_type): | |||
self.item_type = item_type | |||
|
|||
|
|||
class SetType(ConjureType): | |||
item_type = None # type: Type[DecodableType] |
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.
It looks like we're pretty inconsistent elsewhere, but fields should probably be underscored with a @property
method for access.
in response to
I think we should merge this now and then discuss when to cause a break in the |
good to go? |
Sorry, this totally slipped through the cracks. I think getting this in would be great! |
cool. did i miss any changes you requested? the PR is still disapproved by you @ferozco |
Before this PR
After this PR
This PR does a few things: