Skip to content

Commit e2c1029

Browse files
committed
sub _factory -> get_class_instance_by_name
1 parent ea2e7ad commit e2c1029

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

Diff for: plotly/graph_objs/graph_objs.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def to_graph_objs(self, caller=True):
453453
'key_type' in INFO[info_key]['keymeta'][key].keys()):
454454
if INFO[info_key]['keymeta'][key]['key_type'] == 'object':
455455
class_name = KEY_TO_NAME[key]
456-
obj = _factory(class_name)
456+
obj = get_class_instance_by_name(class_name)
457457
if isinstance(obj, PlotlyDict):
458458
if not isinstance(self[key], dict):
459459
try:
@@ -794,7 +794,8 @@ def to_graph_objs(self, caller=True): # TODO TODO TODO! check logic!
794794
"""
795795
for index, entry in enumerate(self):
796796
if isinstance(entry, PlotlyDict):
797-
self[index] = _factory(entry.__class__.__name__, entry)
797+
self[index] = get_class_instance_by_name(
798+
entry.__class__.__name__, entry)
798799
elif isinstance(entry, dict):
799800
if 'type' not in entry: # assume 'scatter' if not given
800801
entry['type'] = 'scatter'
@@ -805,7 +806,7 @@ def to_graph_objs(self, caller=True): # TODO TODO TODO! check logic!
805806
obj=self,
806807
index=index
807808
)
808-
obj = _factory(obj_name)
809+
obj = get_class_instance_by_name(obj_name)
809810
for k, v in list(entry.items()):
810811
obj[k] = v
811812
self[index] = obj
@@ -845,7 +846,7 @@ def to_graph_objs(self, caller=True):
845846
"different kind of graph object.",
846847
)
847848
elif isinstance(entry, dict):
848-
obj = _factory('Annotation')
849+
obj = get_class_instance_by_name('Annotation')
849850
for k, v in list(entry.items()):
850851
obj[k] = v
851852
self[index] = obj
@@ -908,9 +909,9 @@ def to_graph_objs(self, caller=True):
908909
continue # not an XAxis or YAxis object after all
909910
if isinstance(self[key], dict):
910911
if key[:5] == 'xaxis':
911-
obj = _factory('XAxis')
912+
obj = get_class_instance_by_name('XAxis')
912913
else:
913-
obj = _factory('YAxis')
914+
obj = get_class_instance_by_name('YAxis')
914915
for k, v in list(self.pop(key).items()):
915916
obj[k] = v
916917
self[key] = obj # call to super will call 'to_graph_objs'
@@ -1063,7 +1064,7 @@ def force_clean(self, caller=True): # TODO: can't make call to super...
10631064
for name in NAME_TO_KEY.keys()}
10641065

10651066

1066-
def _factory(name, *args, **kwargs):
1067+
def get_class_instance_by_name(name, *args, **kwargs):
10671068
"""All class creation goes through here.
10681069
10691070
Because call signatures for the different classes are different, we have

Diff for: plotly/tests/test_core/test_graph_objs/test_consistency.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ def test_names_in_name_to_key():
2323
def test_names_in_name_to_class():
2424
for key in graph_objs.INFO.keys():
2525
class_name = graph_objs.KEY_TO_NAME[key]
26-
_class = graph_objs._factory(class_name)
26+
_class = graph_objs.get_class_instance_by_name(class_name)

Diff for: plotly/tools.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,11 @@ def get_valid_graph_obj(obj, obj_type=None):
454454
455455
"""
456456
try:
457-
new_obj = graph_objs._factory(obj.__class__.__name__)
457+
new_obj = graph_objs.get_class_instance_by_name(
458+
obj.__class__.__name__)
458459
except KeyError:
459460
try:
460-
new_obj = graph_objs._factory(obj_type)
461+
new_obj = graph_objs.get_class_instance_by_name(obj_type)
461462
except KeyError:
462463
raise exceptions.PlotlyError(
463464
"'{0}' nor '{1}' are recognizable graph_objs.".
@@ -484,7 +485,7 @@ def validate(obj, obj_type):
484485
except KeyError:
485486
pass
486487
try:
487-
test_obj = graph_objs._factory(obj_type, obj)
488+
test_obj = graph_objs.get_class_instance_by_name(obj_type, obj)
488489
except KeyError:
489490
raise exceptions.PlotlyError(
490491
"'{0}' is not a recognizable graph_obj.".

0 commit comments

Comments
 (0)