Skip to content

Commit 1e7c292

Browse files
committed
change INFO[obj] to INFO[obj]['keymeta']
1 parent 54e129a commit 1e7c292

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

plotly/graph_objs/graph_objs.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def strip_style(self):
137137
stripping process, though they made be left empty. This is allowable.
138138
139139
Keys that will be stripped in this process are tagged with
140-
`'type': 'style'` in the INFO dictionary listed in graph_objs_meta.py.
140+
`'type': 'style'` in graph_objs_meta.json.
141141
142142
This process first attempts to convert nested collections from dicts
143143
or lists to subclasses of PlotlyList/PlotlyDict. This process forces
@@ -363,7 +363,7 @@ def strip_style(self):
363363
stripping process, though they made be left empty. This is allowable.
364364
365365
Keys that will be stripped in this process are tagged with
366-
`'type': 'style'` in the INFO dictionary listed in graph_objs_meta.py.
366+
`'type': 'style'` in graph_objs_meta.json.
367367
368368
This process first attempts to convert nested collections from dicts
369369
or lists to subclasses of PlotlyList/PlotlyDict. This process forces
@@ -382,7 +382,7 @@ def strip_style(self):
382382
self[key].strip_style()
383383
else:
384384
try:
385-
if INFO[obj_key][key]['type'] == 'style':
385+
if INFO[obj_key]['keymeta'][key]['type'] == 'style':
386386
if isinstance(self[key], six.string_types):
387387
del self[key]
388388
elif not hasattr(self[key], '__iter__'):
@@ -403,7 +403,7 @@ def get_data(self):
403403
else:
404404
try:
405405
# TODO: Update the JSON
406-
if INFO[obj_key][key]['type'] == 'data':
406+
if INFO[obj_key]['keymeta'][key]['type'] == 'data':
407407
d[key] = val
408408
except KeyError:
409409
pass
@@ -446,14 +446,17 @@ def to_graph_objs(self, caller=True):
446446
err.add_to_error_path(key)
447447
err.prepare()
448448
raise
449-
elif key in INFO[info_key] and 'type' in INFO[info_key][key]:
450-
if INFO[info_key][key]['type'] == 'object':
449+
elif (key in INFO[info_key]['keymeta'] and
450+
'type' in INFO[info_key]['keymeta'][key]):
451+
if INFO[info_key]['keymeta'][key]['type'] == 'object':
451452
class_name = KEY_TO_NAME[key]
452453
obj = _factory(class_name)
453454
if isinstance(obj, PlotlyDict):
454455
if not isinstance(self[key], dict):
455456
try:
456-
val_types = INFO[info_key][key]['val_types']
457+
val_types = (
458+
INFO[info_key]['keymeta'][key]['val_types']
459+
)
457460
except KeyError:
458461
val_types = 'undocumented'
459462
raise exceptions.PlotlyDictValueError(
@@ -468,7 +471,9 @@ def to_graph_objs(self, caller=True):
468471
else: # if not PlotlyDict, it MUST be a PlotlyList
469472
if not isinstance(self[key], list):
470473
try:
471-
val_types = INFO[info_key][key]['val_types']
474+
val_types = (
475+
INFO[info_key]['keymeta'][key]['val_types']
476+
)
472477
except KeyError:
473478
val_types = 'undocumented'
474479
raise exceptions.PlotlyDictValueError( # TODO!!!
@@ -491,7 +496,7 @@ def validate(self, caller=True): # TODO: validate values too?
491496
"""Recursively check the validity of the keys in a PlotlyDict.
492497
493498
The valid keys constitute the entries in each object
494-
dictionary in INFO stored in graph_objs_meta.py.
499+
dictionary in graph_objs_meta.json
495500
496501
The validation process first requires that all nested collections be
497502
converted to the appropriate subclass of PlotlyDict/PlotlyList. Then,
@@ -515,12 +520,13 @@ def validate(self, caller=True): # TODO: validate values too?
515520
err.prepare()
516521
raise
517522
else:
518-
if key in INFO[obj_key]:
519-
if 'type' not in INFO[obj_key][key]:
523+
if key in INFO[obj_key]['keymeta']:
524+
if 'type' not in INFO[obj_key]['keymeta'][key]:
520525
continue # TODO: 'type' may not be documented yet!
521-
if INFO[obj_key][key]['type'] == 'object':
526+
if INFO[obj_key]['keymeta'][key]['type'] == 'object':
522527
try:
523-
val_types = INFO[obj_key][key]['val_types']
528+
val_types = (
529+
INFO[obj_key]['keymeta'][key]['val_types'])
524530
except KeyError:
525531
val_types = 'undocumented'
526532
raise exceptions.PlotlyDictValueError(
@@ -531,15 +537,16 @@ def validate(self, caller=True): # TODO: validate values too?
531537
)
532538
else:
533539
matching_objects = [obj for obj in
534-
INFO if key in INFO[obj]]
540+
INFO if key in INFO[obj]['keymeta']]
535541
notes = ''
536542
if len(matching_objects):
537543
notes += "That key is valid only in these objects:\n\n"
538544
for obj in matching_objects:
539545
notes += "\t{0}".format(KEY_TO_NAME[obj])
540546
try:
541547
notes += '({0}="{1}")\n'.format(
542-
repr(key), INFO[obj][key]['val_types'])
548+
repr(key),
549+
INFO[obj]['keymeta'][key]['val_types'])
543550
except KeyError:
544551
notes += '({0}="..")\n'.format(repr(key))
545552
notes.expandtabs()
@@ -572,7 +579,8 @@ def to_string(self, level=0, indent=4, eol='\n',
572579
string = "{name}(".format(name=self.__class__.__name__)
573580
index = 0
574581
obj_key = NAME_TO_KEY[self.__class__.__name__]
575-
for key in INFO[obj_key]: # this sets the order of the keys! nice.
582+
# This sets the order of the keys! nice.
583+
for key in INFO[obj_key]['keymeta']:
576584
if key in self:
577585
index += 1
578586
string += "{eol}{indent}{key}=".format(
@@ -637,8 +645,9 @@ def get_ordered(self, caller=True):
637645
obj_type = NAME_TO_KEY[self.__class__.__name__]
638646
ordered_dict = OrderedDict()
639647
# grab keys like xaxis1, xaxis2, etc...
640-
unordered_keys = [key for key in self if key not in INFO[obj_type]]
641-
for key in INFO[obj_type]:
648+
unordered_keys = [key for key in self
649+
if key not in INFO[obj_type]['keymeta']]
650+
for key in INFO[obj_type]['keymeta']:
642651
if key in self:
643652
if isinstance(self[key], (PlotlyDict, PlotlyList)):
644653
ordered_dict[key] = self[key].get_ordered(caller=False)
@@ -664,7 +673,8 @@ def force_clean(self, caller=True):
664673
obj_key = NAME_TO_KEY[self.__class__.__name__]
665674
if caller:
666675
self.to_graph_objs(caller=False)
667-
del_keys = [key for key in self if str(key) not in INFO[obj_key]]
676+
del_keys = [key for key in self
677+
if str(key) not in INFO[obj_key]['keymeta']]
668678
for key in del_keys:
669679
del self[key]
670680
keys = list(self.keys())
@@ -935,7 +945,7 @@ def to_string(self, level=0, indent=4, eol='\n',
935945
string = "{name}(".format(name=self.__class__.__name__)
936946
index = 0
937947
obj_key = NAME_TO_KEY[self.__class__.__name__]
938-
for key in INFO[obj_key]:
948+
for key in INFO[obj_key]['keymeta']:
939949
if key in self:
940950
string += "{eol}{indent}{key}=".format(
941951
eol=eol,
@@ -984,7 +994,8 @@ def to_string(self, level=0, indent=4, eol='\n',
984994
index += 1
985995
if index == len(self): # TODO: extraneous...
986996
break
987-
left_over_keys = [key for key in self if key not in INFO[obj_key]]
997+
left_over_keys = [key for key in self
998+
if key not in INFO[obj_key]['keymeta']]
988999
left_over_keys.sort()
9891000
for key in left_over_keys:
9901001
string += "{eol}{indent}{key}=".format(
@@ -1023,7 +1034,8 @@ def force_clean(self, caller=True): # TODO: can't make call to super...
10231034
obj_key = NAME_TO_KEY[self.__class__.__name__]
10241035
if caller:
10251036
self.to_graph_objs(caller=False)
1026-
del_keys = [key for key in self if str(key) not in INFO[obj_key]]
1037+
del_keys = [key for key in self
1038+
if str(key) not in INFO[obj_key]['keymeta']]
10271039
for key in del_keys:
10281040
if (key[:5] == 'xaxis') or (key[:5] == 'yaxis'):
10291041
try:

0 commit comments

Comments
 (0)