Skip to content

Commit 00ffef4

Browse files
committed
Fix two errors in recent codegen updates
1) Copy dict passed to graph obj constructor before popping values from it 2) Don't let Falsey values be converted into None
1 parent 9877e1f commit 00ffef4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

codegen/datatypes.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def build_datatype_py(node):
8181
# -------
8282
buffer.write(
8383
f'from plotly.basedatatypes import {node.name_base_datatype}\n')
84+
buffer.write(
85+
f'import copy\n')
86+
8487

8588
# Write class definition
8689
# ----------------------
@@ -210,12 +213,14 @@ def __init__(self""")
210213
arg = {{}}
211214
elif isinstance(arg, self.__class__):
212215
arg = arg.to_plotly_json()
213-
elif not isinstance(arg, dict):
216+
elif isinstance(arg, dict):
217+
arg = copy.copy(arg)
218+
else:
214219
raise ValueError(\"\"\"\\
215220
The first argument to the {class_name}
216221
constructor must be a dict or
217222
an instance of {class_name}\"\"\")
218-
223+
219224
# Import validators
220225
# -----------------
221226
from plotly.validators{node.parent_dotpath_str} import (
@@ -237,7 +242,7 @@ def __init__(self""")
237242
name_prop = subtype_node.name_property
238243
buffer.write(f"""
239244
v = arg.pop('{name_prop}', None)
240-
self.{name_prop} = {name_prop} or v""")
245+
self.{name_prop} = {name_prop} if {name_prop} is not None else v""")
241246

242247
# ### Literals ###
243248
if literal_nodes:

0 commit comments

Comments
 (0)