2626import collections
2727import json
2828import textwrap
29+
2930from .. import exceptions
30- from .. import utils
31+ from plotly import utils
32+
3133
3234__all__ = ["Data" ,
3335 "Annotations" ,
@@ -268,7 +270,7 @@ def __new__(mcs, name, bases, attrs):
268270 return super (DictMeta , mcs ).__new__ (mcs , name , bases , attrs )
269271
270272
271- class PlotlyList (list ):
273+ class PlotlyList (list , metaclass = ListMeta ):
272274 """A container for PlotlyDicts, inherits from standard list.
273275
274276 Plotly uses lists and dicts as collections to hold information about a
@@ -287,7 +289,6 @@ class PlotlyList(list):
287289
288290
289291 """
290- __metaclass__ = ListMeta
291292
292293 def __init__ (self , * args ):
293294 super (PlotlyList , self ).__init__ (* args )
@@ -493,7 +494,7 @@ def force_clean(self, caller=True):
493494 del_ct += 1
494495
495496
496- class PlotlyDict (dict ):
497+ class PlotlyDict (dict , metaclass = DictMeta ):
497498 """A base dict class for all objects that style a figure in plotly.
498499
499500 A PlotlyDict can be instantiated like any dict object. This class
@@ -506,7 +507,6 @@ class PlotlyDict(dict):
506507 Any available methods that hold for a dict hold for a PlotlyDict.
507508
508509 """
509- __metaclass__ = DictMeta
510510
511511 def __init__ (self , * args , ** kwargs ):
512512 class_name = self .__class__ .__name__
@@ -552,7 +552,7 @@ def update(self, dict1=None, **dict2):
552552 self .to_graph_objs ()
553553
554554 if dict1 is not None :
555- for key , val in dict1 .items ():
555+ for key , val in list ( dict1 .items () ):
556556 if key in self :
557557 if isinstance (self [key ], (PlotlyDict , PlotlyList )):
558558 self [key ].update (val )
@@ -562,7 +562,7 @@ def update(self, dict1=None, **dict2):
562562 self [key ] = val
563563
564564 if len (dict2 ):
565- for key , val in dict2 .items ():
565+ for key , val in list ( dict2 .items () ):
566566 if key in self :
567567 if isinstance (self [key ], (PlotlyDict , PlotlyList )):
568568 self [key ].update (val )
@@ -592,7 +592,7 @@ def strip_style(self):
592592 """
593593 self .to_graph_objs ()
594594 obj_key = NAME_TO_KEY [self .__class__ .__name__ ]
595- keys = self .keys ()
595+ keys = list ( self .keys () )
596596 for key in keys :
597597 if isinstance (self [key ], (PlotlyDict , PlotlyList )):
598598 self [key ].strip_style ()
@@ -611,7 +611,7 @@ def get_data(self):
611611 class_name = self .__class__ .__name__
612612 obj_key = NAME_TO_KEY [class_name ]
613613 d = dict ()
614- for key , val in self .items ():
614+ for key , val in list ( self .items () ):
615615 if isinstance (val , (PlotlyDict , PlotlyList )):
616616 d [key ] = val .get_data ()
617617 else :
@@ -620,13 +620,13 @@ def get_data(self):
620620 d [key ] = val
621621 except KeyError :
622622 pass
623- keys = d .keys ()
623+ keys = list ( d .keys () )
624624 for key in keys :
625625 if isinstance (d [key ], (dict , list )):
626626 if len (d [key ]) == 0 :
627627 del d [key ]
628628 if len (d ) == 1 :
629- d = d .values ()[0 ]
629+ d = list ( d .values () )[0 ]
630630 return d
631631
632632 def to_graph_objs (self , caller = True ):
@@ -639,7 +639,7 @@ def to_graph_objs(self, caller=True):
639639
640640 """
641641 info_key = NAME_TO_KEY [self .__class__ .__name__ ]
642- keys = self .keys ()
642+ keys = list ( self .keys () )
643643 for key in keys :
644644 if isinstance (self [key ], (PlotlyDict , PlotlyList )):
645645 try :
@@ -665,7 +665,7 @@ def to_graph_objs(self, caller=True):
665665 val_types = val_types ,
666666 notes = "value needs to be dictionary-like"
667667 )
668- for k , v in self .pop (key ).items ():
668+ for k , v in list ( self .pop (key ).items () ):
669669 obj [k ] = v # finish up momentarily...
670670 else : # if not PlotlyDict, it MUST be a PlotlyList
671671 if not isinstance (self [key ], list ):
@@ -708,7 +708,7 @@ def validate(self, caller=True): # TODO: validate values too?
708708 err .prepare ()
709709 raise
710710 obj_key = NAME_TO_KEY [self .__class__ .__name__ ]
711- for key , val in self .items ():
711+ for key , val in list ( self .items () ):
712712 if isinstance (val , (PlotlyDict , PlotlyList )):
713713 try :
714714 val .validate (caller = False )
@@ -843,7 +843,7 @@ def force_clean(self, caller=True):
843843 del_keys = [key for key in self if str (key ) not in INFO [obj_key ]]
844844 for key in del_keys :
845845 del self [key ]
846- keys = self .keys ()
846+ keys = list ( self .keys () )
847847 for key in keys :
848848 try :
849849 self [key ].force_clean (caller = False ) # TODO: add error handling
@@ -889,7 +889,7 @@ def to_graph_objs(self, caller=True): # TODO TODO TODO! check logic!
889889 index = index
890890 )
891891 obj = NAME_TO_CLASS [obj_name ]() # don't hide if KeyError!
892- for k , v in entry .items ():
892+ for k , v in list ( entry .items () ):
893893 obj [k ] = v
894894 self [index ] = obj
895895 if not isinstance (self [index ], PlotlyTrace ): # Trace ONLY!!!
@@ -939,7 +939,7 @@ def to_graph_objs(self, caller=True):
939939 )
940940 elif isinstance (entry , dict ):
941941 obj = Annotation ()
942- for k , v in entry .items ():
942+ for k , v in list ( entry .items () ):
943943 obj [k ] = v
944944 self [index ] = obj
945945 else :
@@ -1253,7 +1253,7 @@ def to_graph_objs(self, caller=True):
12531253 appropriate `kind`.
12541254
12551255 """
1256- keys = self .keys ()
1256+ keys = list ( self .keys () )
12571257 for key in keys :
12581258 if key [:5 ] in ['xaxis' , 'yaxis' ]: # allows appended integers!
12591259 try :
@@ -1267,7 +1267,7 @@ def to_graph_objs(self, caller=True):
12671267 obj = XAxis ()
12681268 else :
12691269 obj = YAxis ()
1270- for k , v in self .pop (key ).items ():
1270+ for k , v in list ( self .pop (key ).items () ):
12711271 obj [k ] = v
12721272 self [key ] = obj # call to super will call 'to_graph_objs'
12731273 super (Layout , self ).to_graph_objs (caller = caller )
@@ -1366,7 +1366,7 @@ def force_clean(self, caller=True): # TODO: can't make call to super...
13661366 del self [key ]
13671367 else :
13681368 del self [key ]
1369- keys = self .keys ()
1369+ keys = list ( self .keys () )
13701370 for key in keys :
13711371 try :
13721372 self [key ].force_clean (caller = False ) # TODO error handling??
0 commit comments