Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Import Value, input_float, input_value from core #3

Merged
merged 14 commits into from
May 22, 2017

Conversation

jbwhite
Copy link
Contributor

@jbwhite jbwhite commented May 15, 2017

Initially moved here to support extracting measurements from core, although the dependent code will likely be removed from measurements.

If we still want these moved into blmath we can merge this -- otherwise we could just leave them in core.

@jbwhite jbwhite requested review from algrs and sashaverma May 15, 2017 19:32
super(BlmathJSONDecoder, self).__init__()
self.register(self.decode_supported_types)

def decode_supported_types(self, dct):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied over from core bodylabs.serialization.json and I believe can be deleted from core as part of the removal of measurements since the only SUPPORTED_TYPE is Value, which is now part of blmath.

@@ -0,0 +1,46 @@
'''
If an object defines for_json(), it will be serialized as what that returns.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment probably makes most sense in Haiti-serialization.

super(BlmathJSONDecoder, self).__init__()
self.register(self.decode_supported_types)

def decode_supported_types(self, dct):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's clean this up some, since it's just Value:

from blmath.value import Value

def decode_value(self, dct):
    if "__value__" in  dct.keys():
        return Value.from_json(dct)

We can leave it as is in core, so we have the example for the future and so that bodylabs.serialization.json continues to handle values as advertised. But here in measurements, let's be nice and simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done -- also removed a test for an error that the simplified decoder doesn't worry about.

x_str = json.dumps({'__value__': {'value': 25.0, 'units': 'cm'}, 'foo': 'bar'})
with self.assertRaises(TypeError):
json.loads(x_str)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed test because we no longer raise this error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jbwhite jbwhite merged commit 9acf81a into master May 22, 2017
@jbwhite jbwhite deleted the 122_import_inputs_value branch May 23, 2017 19:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants