Skip to content

Commit c7f3ad6

Browse files
committed
sub globals() for dynamically-created NAME_TO_CLASS dict
1 parent 906d7ff commit c7f3ad6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

plotly/graph_objs/graph_objs.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,11 @@ def force_clean(self, caller=True): # TODO: can't make call to super...
10581058
Layout = patch_Layout(Layout)
10591059

10601060

1061-
# (4) Class-generating function
1061+
# (4) NAME_TO_CLASS dict and class-generating function
1062+
NAME_TO_CLASS = {name: getattr(sys.modules[__name__], name)
1063+
for name in NAME_TO_KEY.keys()}
1064+
1065+
10621066
def _factory(name, *args, **kwargs):
10631067
"""All class creation goes through here.
10641068
@@ -1067,11 +1071,12 @@ def _factory(name, *args, **kwargs):
10671071
allows instantiation errors to occur naturally.
10681072
10691073
"""
1074+
print sys.modules[__name__], name
10701075
if args and kwargs:
1071-
return globals()[name](*args, **kwargs)
1076+
return NAME_TO_CLASS[name](*args, **kwargs)
10721077
elif args:
1073-
return globals()[name](*args)
1078+
return NAME_TO_CLASS[name](*args)
10741079
elif kwargs:
1075-
return globals()[name](**kwargs)
1080+
return NAME_TO_CLASS[name](**kwargs)
10761081
else:
1077-
return globals()[name]()
1082+
return NAME_TO_CLASS[name]()

0 commit comments

Comments
 (0)