Skip to content

Commit a89dcb5

Browse files
author
Jon M. Mease
committed
Rework handling of unknown kwargs in datatype classes
kwargs may now be handled after the constructor is called, this is needed to fix a bug with specifying the first axis args as xaxis1 (rather than xaxis).
1 parent c6d6540 commit a89dcb5

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

Diff for: codegen/datatypes.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def __init__(self""")
190190
add_docstring(buffer, node, header=header)
191191

192192
buffer.write(f"""
193-
super().__init__('{node.name_property}', **kwargs)
193+
super().__init__('{node.name_property}')
194194
195195
# Import validators
196196
# -----------------
@@ -227,6 +227,13 @@ def __init__(self""")
227227
buffer.write(f"""
228228
self._props['{lit_name}'] = '{lit_val}'""")
229229

230+
buffer.write(f"""
231+
232+
# Process unknown kwargs
233+
# ----------------------
234+
self._process_kwargs(**kwargs)
235+
""")
236+
230237
# Return source string
231238
# --------------------
232239
return buffer.getvalue()

Diff for: plotly/basedatatypes.py

+32-14
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ def __init__(self, plotly_name, **kwargs):
20632063
"""
20642064
# Validate inputs
20652065
# ---------------
2066-
self._raise_on_invalid_property_error(*kwargs.keys())
2066+
self._process_kwargs(**kwargs)
20672067

20682068
# Store params
20692069
# ------------
@@ -2107,6 +2107,12 @@ def __init__(self, plotly_name, **kwargs):
21072107
# type: Dict[Tuple[Tuple[Union[str, int]]], List[Callable]]
21082108
self._change_callbacks = {}
21092109

2110+
def _process_kwargs(self, **kwargs):
2111+
"""
2112+
Process any extra kwargs that are not predefined as constructor params
2113+
"""
2114+
self._raise_on_invalid_property_error(*kwargs.keys())
2115+
21102116
@property
21112117
def plotly_name(self):
21122118
"""
@@ -3145,26 +3151,38 @@ def __init__(self, plotly_name, **kwargs):
31453151
# ---------------
31463152
assert plotly_name == 'layout'
31473153

3148-
# Compute invalid kwargs
3149-
# ----------------------
3150-
# Pass to parent for error handling
3151-
invalid_kwargs = {
3152-
k: v
3153-
for k, v in kwargs.items()
3154-
if not self._subplotid_prop_re.fullmatch(k)
3155-
}
3156-
super().__init__(plotly_name, **invalid_kwargs)
3154+
# Call superclass constructor
3155+
# ---------------------------
3156+
super().__init__(plotly_name)
31573157

31583158
# Initialize _subplotid_props
31593159
# ---------------------------
31603160
# This is a set storing the names of the layout's dynamic subplot
31613161
# properties
31623162
self._subplotid_props = set()
31633163

3164-
# Process subplot properties
3165-
# --------------------------
3166-
# The remaining kwargs are valid subplot properties
3167-
for prop, value in kwargs.items():
3164+
# Process kwargs
3165+
# --------------
3166+
self._process_kwargs(**kwargs)
3167+
3168+
def _process_kwargs(self, **kwargs):
3169+
"""
3170+
Process any extra kwargs that are not predefined as constructor params
3171+
"""
3172+
unknown_kwargs = {
3173+
k: v
3174+
for k, v in kwargs.items()
3175+
if not self._subplotid_prop_re.fullmatch(k)
3176+
}
3177+
super()._process_kwargs(**unknown_kwargs)
3178+
3179+
subplot_kwargs = {
3180+
k: v
3181+
for k, v in kwargs.items()
3182+
if self._subplotid_prop_re.fullmatch(k)
3183+
}
3184+
3185+
for prop, value in subplot_kwargs.items():
31683186
self._set_subplotid_prop(prop, value)
31693187

31703188
def _set_subplotid_prop(self, prop, value):

0 commit comments

Comments
 (0)