From 4c842e06a1187f043fee396f3d39081f34317521 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 21 Aug 2010 13:44:05 -0400 Subject: [PATCH] Tracked down problems saving playlists with loaded curves to numpy.dtype --- hooke/playlist.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/hooke/playlist.py b/hooke/playlist.py index 9ee3125..b996a5f 100644 --- a/hooke/playlist.py +++ b/hooke/playlist.py @@ -27,6 +27,24 @@ import os import os.path import types +if False: # YAML dump debugging code + """To help isolate data types etc. that give YAML problems. + + This is usually caused by external C modules (e.g. numpy) that + define new types (e.g. numpy.dtype) which YAML cannot inspect. + """ + import yaml.representer + import sys + def ignore_aliases(data): + print data, type(data) + sys.stdout.flush() + if data in [None, ()]: + return True + if isinstance(data, (str, unicode, bool, int, float)): + return True + yaml.representer.SafeRepresenter.ignore_aliases = staticmethod( + ignore_aliases) + import yaml from yaml.representer import RepresenterError @@ -103,10 +121,10 @@ class NoteIndexList (list): continue try: yaml.dump((k,v)) - except (TypeError, RepresenterError), e: + except RepresenterError, e: raise NotImplementedError( - 'cannot convert %s.%s = %s (%s) to YAML' - % (owner.__class__.__name__, k, v, type(v))) + 'cannot convert %s.%s = %s (%s) to YAML\n%s' + % (owner.__class__.__name__, k, v, type(v), e)) def _setup_item(self, item): """Perform any required initialization before returning an item. @@ -197,10 +215,9 @@ class Playlist (NoteIndexList): self._ignored_attrs.extend([ '_item_ignored_attrs', '_item_default_attrs', '_loaded']) - self._item_ignored_attrs = [] + self._item_ignored_attrs = ['data'] self._item_default_attrs = { 'command_stack': [], - 'data': None, 'driver': None, 'info': {}, 'name': None, -- 2.26.2