Skip to content

Conversation

faerot
Copy link
Contributor

@faerot faerot commented May 22, 2014

This will make precise python types serialization possible.

This will make precise python types serialization possible.
@faerot
Copy link
Contributor Author

faerot commented May 22, 2014

Detailed motivation here:
#98

@methane
Copy link
Member

methane commented May 22, 2014

Could you pack object which type is like following?

class MyList(list):
    __slots__ = ()

I think I can't support precise packing Python types without breaking backward compatibility...

@faerot
Copy link
Contributor Author

faerot commented May 22, 2014

Hm... indeed, looks like in this case such class with be serialized as list and class information will be lost. The solution I see is instead of "distinguish_tuple" argument it is better to add argument "precise_mode" and if that one is set, it will make an accurate type checks:

type(x) is list

instead of:

isinstance(x, list)

That should allow to do accurate serialization and keep the backward compatibility. What do you think about that?

@methane
Copy link
Member

methane commented May 22, 2014

msgpack-python API is come from simplejson.

http://simplejson.readthedocs.org/en/latest/#encoders-and-decoders

If tuple_as_array is true (default: True), tuple (and subclasses) will be encoded as JSON arrays.
Changed in version 2.2.0: tuple_as_array is new in 2.2.0.

I'll follow it.

@methane
Copy link
Member

methane commented May 22, 2014

If you want to serialize Python types completely, use pickle.
msgpack and JSON is not for such purpose.

@faerot
Copy link
Contributor Author

faerot commented May 22, 2014

Pickle can't be used in my case, becase if is not safe when data comes from untrusted source.

When precise_mode flag is set, serialization will be as precise as
possible - type checks will be exact (type(..) is ... instead of
isinstance(..., ...) and tuple will be treated as undefined type. This
mode is to make accurate object serialization possible.
@methane methane closed this Jan 25, 2015
@methane methane reopened this Jan 25, 2015
:param bool precise_mode:
If set to true, types will be checked to be exact. Derived classes
from serializeable types will not be serialized and will be
treated as unsupported type and forwarded to default.
Copy link
Member

Choose a reason for hiding this comment

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

I don't like precise_mode name since it doesn't mention about types.
What about strict_types?

@methane methane merged commit b877ce2 into msgpack:master Jan 25, 2016
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

Successfully merging this pull request may close these issues.

2 participants