From 18393ce4e0d081f9b213df9f5ce5f92a61b3d39a Mon Sep 17 00:00:00 2001 From: Alex Rubinsteyn Date: Tue, 6 Oct 2026 11:56:43 -0400 Subject: [PATCH 1/2] Fix docstrings copied from sibling packages; bump to 1.1.2 Serializable's inherited docstrings named VariantCollection, Genome and PyEnsembl, which leaked into downstream API docs (e.g. PyEnsembl's Genome.read_json_file). Make them generic, and fix a code comment that still named the old `_KEYWORD_ALIASES` hook. Adds a write_json_file/read_json_file round-trip test (previously uncovered). Fixes #17 Claude-Session: https://claude.ai/code/session_01JRDMg3F5kNKmnjv5jvQBgr --- serializable/serializable.py | 11 +++++------ serializable/version.py | 2 +- tests/test_object.py | 6 ++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/serializable/serializable.py b/serializable/serializable.py index e961e21..16cac60 100644 --- a/serializable/serializable.py +++ b/serializable/serializable.py @@ -24,7 +24,7 @@ class Serializable: """ - Base class for all PyEnsembl objects which provides default + Base class for user-defined objects which provides default methods such as to_json, from_json, __reduce__, and from_dict Relies on the following condition: @@ -78,7 +78,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 +99,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 +112,7 @@ 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 JSON and write it to the text file at `path`. """ with open(path, "w") as f: f.write(self.to_json()) @@ -121,7 +120,7 @@ def write_json_file(self, path): @classmethod def read_json_file(cls, path): """ - Construct a VariantCollection from a JSON file. + Construct an instance of this class from the JSON file at `path`. """ with open(path) as f: json_string = f.read() diff --git a/serializable/version.py b/serializable/version.py index 4b8e122..e52182c 100644 --- a/serializable/version.py +++ b/serializable/version.py @@ -1,4 +1,4 @@ -__version__ = "1.1.1" +__version__ = "1.1.2" def print_version(): diff --git a/tests/test_object.py b/tests/test_object.py index 3a73b0a..93da2da 100644 --- a/tests/test_object.py +++ b/tests/test_object.py @@ -44,3 +44,9 @@ def test_object_to_json(): def test_object_pickle(): eq_(instance, pickle.loads(pickle.dumps(instance))) + + +def test_object_json_file(tmp_path): + path = tmp_path / "instance.json" + instance.write_json_file(path) + eq_(instance, A.read_json_file(path)) From 5eb7c8b8c01e7a62db68ce6dafe34f3a438c8c94 Mon Sep 17 00:00:00 2001 From: Alex Rubinsteyn Date: Tue, 6 Oct 2026 15:47:44 -0400 Subject: [PATCH 2/2] Fix two more inaccurate docstrings from #14 Serializable provides a default to_dict, so it doesn't need a user-defined one; also fix the grammar in to_serializable_repr's helper docstring. Claude-Session: https://claude.ai/code/session_01JyZ1WTFWJ3EZ41QdYzKwGP --- serializable/helpers.py | 4 ++-- serializable/serializable.py | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) 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 16cac60..385d856 100644 --- a/serializable/serializable.py +++ b/serializable/serializable.py @@ -27,9 +27,7 @@ class Serializable: Base class for user-defined objects 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):