Skip to content

Commit

Permalink
moved **kwargs to bottom of constructor signatures // super() -> supe…
Browse files Browse the repository at this point in the history
…r(className, self)
  • Loading branch information
Kully committed May 14, 2018
1 parent b86d44b commit f0d863d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion codegen/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def __init__(self""")
add_docstring(buffer, node, header=header)

buffer.write(f"""
super().__init__('{node.name_property}')
super({node.name_base_datatype}, self).__init__('{node.name_property}')
# Import validators
# -----------------
Expand Down
2 changes: 1 addition & 1 deletion codegen/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, data=None, layout=None, frames=None):
frames
{frames_description}
\"\"\"
super().__init__(data, layout, frames)
super({base_classname}, self).__init__(data, layout, frames)
""")

# ### add_trace methods for each trace type ###
Expand Down
7 changes: 5 additions & 2 deletions codegen/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def __init__(self, plotly_name={params['plotly_name']},
# ### Write constructor ###
buffer.write(f"""
super({superclass_name}, self).__init__(plotly_name=plotly_name,
parent_name=parent_name,
**kwargs""")
parent_name=parent_name""")

# Write out remaining constructor parameters
for attr_name, attr_val in params.items():
Expand All @@ -66,6 +65,10 @@ def __init__(self, plotly_name={params['plotly_name']},
buffer.write(f""",
{attr_name}={attr_val}""")

# write **kwargs at the end to make Py2 compatible
buffer.write(f""",
**kwargs""")

buffer.write(')')

# ### Return buffer's string ###
Expand Down
30 changes: 22 additions & 8 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
Undefined = object()


# back-port of fullmatch from Py3.4+
def fullmatch(regex, string, flags=0):
"""Emulate python-3.4 re.fullmatch()."""
return re.match("(?:" + regex + r")\Z", string, flags=flags)


class BaseFigure(object):
"""
Base class for all figure types (both widget and non-widget)
Expand Down Expand Up @@ -742,7 +748,8 @@ def _str_to_dict_path(key_path_str):
bracket_re = re.compile('(.*)\[(\d+)\]')
key_path2 = []
for key in key_path:
match = bracket_re.fullmatch(key)
match = fullmatch(bracket_re.pattern, key)
#match = bracket_re.fullmatch(key)
if match:
key_path2.extend(match.groups())
else:
Expand Down Expand Up @@ -3389,14 +3396,16 @@ def _process_kwargs(self, **kwargs):
unknown_kwargs = {
k: v
for k, v in kwargs.items()
if not self._subplotid_prop_re.fullmatch(k)
# if not self._subplotid_prop_re.fullmatch(k)
if not fullmatch(self._subplotid_prop_re.pattern, k)
}
super(BaseLayoutHierarchyType, self)._process_kwargs(**unknown_kwargs)

subplot_kwargs = {
k: v
for k, v in kwargs.items()
if self._subplotid_prop_re.fullmatch(k)
# if self._subplotid_prop_re.fullmatch(k)
if fullmatch(self._subplotid_prop_re.pattern, k)
}

for prop, value in subplot_kwargs.items():
Expand All @@ -3416,7 +3425,9 @@ def _set_subplotid_prop(self, prop, value):
# Get regular expression match
# ----------------------------
# Note: we already tested that match exists in the constructor
match = self._subplotid_prop_re.fullmatch(prop)
# match = self._subplotid_prop_re.fullmatch(prop)
match = fullmatch(self._subplotid_prop_re.pattern, prop)

subplot_prop = match.group(1)
suffix_digit = int(match.group(2))

Expand Down Expand Up @@ -3477,7 +3488,8 @@ def _strip_subplot_suffix_of_1(self, prop):
# Handle subplot suffix digit of 1
# --------------------------------
# Remove digit of 1 from subplot id (e.g.. xaxis1 -> xaxis)
match = self._subplotid_prop_re.fullmatch(prop)
# match = self._subplotid_prop_re.fullmatch(prop)
match = fullmatch(self._subplotid_prop_re.pattern, prop)

if match:
subplot_prop = match.group(1)
Expand Down Expand Up @@ -3529,7 +3541,8 @@ def __setitem__(self, prop, value):

# Check for subplot assignment
# ----------------------------
match = self._subplotid_prop_re.fullmatch(prop)
# match = self._subplotid_prop_re.fullmatch(prop)
match = fullmatch(self._subplotid_prop_re.pattern, prop)
if match is None:
# Set as ordinary property
super(BaseLayoutHierarchyType, self).__setitem__(prop, value)
Expand All @@ -3543,7 +3556,8 @@ def __setattr__(self, prop, value):
"""
# Check for subplot assignment
# ----------------------------
match = self._subplotid_prop_re.fullmatch(prop)
# match = self._subplotid_prop_re.fullmatch(prop)
match = fullmatch(self._subplotid_prop_re.pattern, prop)
if match is None:
# Set as ordinary property
super(BaseLayoutHierarchyType, self).__setattr__(prop, value)
Expand All @@ -3565,7 +3579,7 @@ class BaseTraceHierarchyType(BasePlotlyType):
"""

def __init__(self, plotly_name, **kwargs):
super(BasePlotlyType, self).__init__(plotly_name, **kwargs)
super(BaseTraceHierarchyType, self).__init__(plotly_name, **kwargs)

def _send_prop_set(self, prop_path_str, val):
if self.parent:
Expand Down
1 change: 0 additions & 1 deletion plotly/graph_objs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
from ._frame import Frame
from ._figure import Figure


try:
import ipywidgets
from ._figurewidget import FigureWidget
Expand Down

0 comments on commit f0d863d

Please sign in to comment.