diff --git a/README.md b/README.md index 7f22289..eee644d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ A derived class must either: - have a member data matching the name of each argument to `__init__` - provide a user-defined `to_dict()` method which returns a dictionary whose keys match the arguments to `__init__` -If you change the keyword arguments to a class which derives from `Serializable` but would like to be able to deserialize older JSON representations then you can define a class-level dictionary called `_KEYWORD_ALIASES` which maps old keywords to new names (or `None` if a keyword was removed). +If you change the keyword arguments to a class which derives from `Serializable` but would like to be able to deserialize older JSON representations then you can define a class-level dictionary called `_SERIALIZABLE_KEYWORD_ALIASES` which maps old keywords to new names (or `None` if a keyword was removed). ## `DataclassSerializable` for `@dataclass` subclasses @@ -42,6 +42,6 @@ The on-wire JSON format is identical to `Serializable`, so mixed codebases inter ## Limitations -- Serializable objects must inherit from `Serializable`, be tuples or namedtuples, be serializble primitive types such as dict, list, int, float, or str. +- Serializable objects must inherit from `Serializable`, be tuples or namedtuples, be serializable primitive types such as dict, list, int, float, or str. - The serialized representation of objects relies on reserved keywords (such as `"__name__"`, and `"__class__"`), so dictionaries are expected to not contain any keys which begin with two underscores. diff --git a/serializable/helpers.py b/serializable/helpers.py index 289185c..2d0939a 100644 --- a/serializable/helpers.py +++ b/serializable/helpers.py @@ -228,8 +228,8 @@ def list_to_serializable_repr(x): def to_dict(obj): """ - If value wasn't isn't a primitive scalar or collection then it needs to - either implement to_dict (instances of Serializable) or has member + If value isn't a primitive scalar or collection then it needs to + either implement to_dict (instances of Serializable) or have member data matching each required arg of __init__. """ if isinstance(obj, dict): diff --git a/serializable/serializable.py b/serializable/serializable.py index e961e21..aa901fc 100644 --- a/serializable/serializable.py +++ b/serializable/serializable.py @@ -24,12 +24,10 @@ class Serializable: """ - Base class for all PyEnsembl objects which provides default - methods such as to_json, from_json, __reduce__, and from_dict + Base class which provides default methods such as to_json, from_json, + __reduce__, and from_dict. - Relies on the following condition: - (1) a user-defined to_dict method - (2) the keys of to_dict() must match the arguments to __init__ + Relies on the keys of to_dict() matching the arguments to __init__. """ def __str__(self): @@ -78,7 +76,7 @@ def _update_kwargs(cls, kwargs): Rename any old keyword arguments to preserve backwards compatibility """ # check every class in the inheritance chain for its own - # definition of _KEYWORD_ALIASES + # definition of _SERIALIZABLE_KEYWORD_ALIASES for klass in cls.mro(): keyword_rename_dict = getattr(klass, "_SERIALIZABLE_KEYWORD_ALIASES", {}) for old_name, new_name in keyword_rename_dict.items(): @@ -99,7 +97,7 @@ def from_dict(cls, state_dict): def to_json(self): """ - Returns a string containing a JSON representation of this Genome. + Returns a string containing a JSON representation of this object. """ return to_json(self) @@ -112,8 +110,8 @@ def from_json(cls, json_string): def write_json_file(self, path): """ - Serialize this VariantCollection to a JSON representation and write it - out to a text file. + Serialize this object to a JSON representation and write it out to a + text file. """ with open(path, "w") as f: f.write(self.to_json()) @@ -121,7 +119,7 @@ def write_json_file(self, path): @classmethod def read_json_file(cls, path): """ - Construct a VariantCollection from a JSON file. + Construct an instance from a JSON file. """ with open(path) as f: json_string = f.read() @@ -132,8 +130,4 @@ def __reduce__(self): Overriding this method directs the default pickler to reconstruct this object using our from_dict method. """ - - # I wish I could just return (self.from_dict, (self.to_dict(),) but - # Python 2 won't pickle the class method from_dict so instead have to - # use globally defined functions. return (from_serializable_repr, (to_serializable_repr(self),)) diff --git a/serializable/version.py b/serializable/version.py index 7c0f2bf..4b8e122 100644 --- a/serializable/version.py +++ b/serializable/version.py @@ -1,4 +1,4 @@ -__version__ = "1.1.0" +__version__ = "1.1.1" def print_version():