Skip to content
Snippets Groups Projects
Commit cf12878b authored by James Johnson's avatar James Johnson
Browse files

Removed traits version from json output

parent 0138ae30
No related branches found
No related tags found
1 merge request!152Removed __traits_version__ from json files
import json
from traits.api import HasStrictTraits
from collections import Iterable
class WorkflowWriter(HasStrictTraits):
......@@ -91,10 +92,30 @@ class WorkflowWriter(HasStrictTraits):
def traits_to_dict(traits_obj):
"""Converts a traits class into a dict, removing the pesky
traits version."""
def pop_traits(dictionary):
"""Recursively remove the __traits_version__ attribute
from dictionary."""
try:
dictionary.pop("__traits_version__")
except KeyError:
pass
for key in dictionary:
# If we have a dict, remove the traits version
if isinstance(dictionary[key], dict):
pop_traits(dictionary[key])
# If we have a non-dict which contains a dict, remove traits from
# that as well
elif isinstance(dictionary[key], Iterable):
for element in dictionary[key]:
if isinstance(element, dict):
pop_traits(element)
return dictionary
state = traits_obj.__getstate__()
try:
state.pop("__traits_version__")
except KeyError:
pass
state = pop_traits(state)
return state
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment