Skip to content

Commit 8756f5e

Browse files
author
Jon M. Mease
committed
Review and cleanup of codegen package
1 parent 2c68db5 commit 8756f5e

File tree

7 files changed

+1449
-655
lines changed

7 files changed

+1449
-655
lines changed

_plotly_utils/basevalidators.py

+72-40
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ def type_str(v):
7676
# Validators
7777
# ----------
7878
class BaseValidator:
79-
def __init__(self, plotly_name, parent_name):
79+
def __init__(self, plotly_name, parent_name, role=None, **_):
8080
self.parent_name = parent_name
8181
self.plotly_name = plotly_name
82+
self.role = role
8283

8384
def validate_coerce(self, v):
8485
raise NotImplementedError()
@@ -129,8 +130,9 @@ class DataArrayValidator(BaseValidator):
129130
},
130131
"""
131132

132-
def __init__(self, plotly_name, parent_name, **_):
133-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
133+
def __init__(self, plotly_name, parent_name, **kwargs):
134+
super().__init__(plotly_name=plotly_name,
135+
parent_name=parent_name, **kwargs)
134136

135137
def description(self):
136138
return ("""\
@@ -163,8 +165,12 @@ class EnumeratedValidator(BaseValidator):
163165
]
164166
},
165167
"""
166-
def __init__(self, plotly_name, parent_name, values, array_ok=False, coerce_number=False, **_):
167-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
168+
def __init__(self, plotly_name, parent_name, values,
169+
array_ok=False,
170+
coerce_number=False,
171+
**kwargs):
172+
super().__init__(plotly_name=plotly_name,
173+
parent_name=parent_name, **kwargs)
168174

169175
# coerce_number is rarely used and not implemented
170176
self.coerce_number = coerce_number
@@ -298,8 +304,9 @@ class BooleanValidator(BaseValidator):
298304
]
299305
},
300306
"""
301-
def __init__(self, plotly_name, parent_name, **_):
302-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
307+
def __init__(self, plotly_name, parent_name, **kwargs):
308+
super().__init__(plotly_name=plotly_name,
309+
parent_name=parent_name, **kwargs)
303310

304311
def description(self):
305312
return ("""\
@@ -329,8 +336,10 @@ class NumberValidator(BaseValidator):
329336
]
330337
},
331338
"""
332-
def __init__(self, plotly_name, parent_name, min=None, max=None, array_ok=False, **_):
333-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
339+
def __init__(self, plotly_name, parent_name,
340+
min=None, max=None, array_ok=False, **kwargs):
341+
super().__init__(plotly_name=plotly_name,
342+
parent_name=parent_name, **kwargs)
334343

335344
# Handle min
336345
if min is None and max is not None:
@@ -417,8 +426,10 @@ class IntegerValidator(BaseValidator):
417426
]
418427
},
419428
"""
420-
def __init__(self, plotly_name, parent_name, min=None, max=None, array_ok=False, **_):
421-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
429+
def __init__(self, plotly_name, parent_name,
430+
min=None, max=None, array_ok=False, **kwargs):
431+
super().__init__(plotly_name=plotly_name,
432+
parent_name=parent_name, **kwargs)
422433

423434
# Handle min
424435
if min is None and max is not None:
@@ -512,8 +523,11 @@ class StringValidator(BaseValidator):
512523
]
513524
},
514525
"""
515-
def __init__(self, plotly_name, parent_name, no_blank=False, strict=False, array_ok=False, values=None, **_):
516-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
526+
def __init__(self, plotly_name, parent_name,
527+
no_blank=False, strict=False, array_ok=False, values=None,
528+
**kwargs):
529+
super().__init__(plotly_name=plotly_name,
530+
parent_name=parent_name, **kwargs)
517531
self.no_blank = no_blank
518532
self.strict = strict # Not implemented. We're always strict
519533
self.array_ok = array_ok
@@ -613,8 +627,10 @@ class ColorValidator(BaseValidator):
613627
"slateblue", "slategray", "slategrey", "snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato",
614628
"turquoise", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen"]
615629

616-
def __init__(self, plotly_name, parent_name, array_ok=False, colorscale_path=None, **_):
617-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
630+
def __init__(self, plotly_name, parent_name,
631+
array_ok=False, colorscale_path=None, **kwargs):
632+
super().__init__(plotly_name=plotly_name,
633+
parent_name=parent_name, **kwargs)
618634
self.colorscale_path = colorscale_path
619635
self.array_ok = array_ok
620636

@@ -718,8 +734,9 @@ class ColorlistValidator(BaseValidator):
718734
]
719735
}
720736
"""
721-
def __init__(self, plotly_name, parent_name, **_):
722-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
737+
def __init__(self, plotly_name, parent_name, **kwargs):
738+
super().__init__(plotly_name=plotly_name,
739+
parent_name=parent_name, **kwargs)
723740

724741
def description(self):
725742
return ("""\
@@ -758,8 +775,9 @@ class ColorscaleValidator(BaseValidator):
758775
named_colorscales = ['Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', 'Picnic',
759776
'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis']
760777

761-
def __init__(self, plotly_name, parent_name, **_):
762-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
778+
def __init__(self, plotly_name, parent_name, **kwargs):
779+
super().__init__(plotly_name=plotly_name,
780+
parent_name=parent_name, **kwargs)
763781

764782
def description(self):
765783
desc = """\
@@ -817,8 +835,9 @@ class AngleValidator(BaseValidator):
817835
]
818836
},
819837
"""
820-
def __init__(self, plotly_name, parent_name, **_):
821-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
838+
def __init__(self, plotly_name, parent_name, **kwargs):
839+
super().__init__(plotly_name=plotly_name,
840+
parent_name=parent_name, **kwargs)
822841

823842
def description(self):
824843
desc = """\
@@ -851,8 +870,9 @@ class SubplotidValidator(BaseValidator):
851870
"otherOpts": []
852871
},
853872
"""
854-
def __init__(self, plotly_name, parent_name, dflt, **_):
855-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
873+
def __init__(self, plotly_name, parent_name, dflt, **kwargs):
874+
super().__init__(plotly_name=plotly_name,
875+
parent_name=parent_name, **kwargs)
856876
self.base = dflt
857877
self.regex = dflt + "(\d*)"
858878

@@ -904,8 +924,10 @@ class FlaglistValidator(BaseValidator):
904924
]
905925
},
906926
"""
907-
def __init__(self, plotly_name, parent_name, flags, extras=None, array_ok=False, **_):
908-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
927+
def __init__(self, plotly_name, parent_name, flags,
928+
extras=None, array_ok=False, **kwargs):
929+
super().__init__(plotly_name=plotly_name,
930+
parent_name=parent_name, **kwargs)
909931
self.flags = flags
910932
self.extras = extras if extras is not None else []
911933
self.array_ok = array_ok
@@ -988,8 +1010,10 @@ class AnyValidator(BaseValidator):
9881010
]
9891011
},
9901012
"""
991-
def __init__(self, plotly_name, parent_name, values=None, array_ok=False, **_):
992-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
1013+
def __init__(self, plotly_name, parent_name,
1014+
values=None, array_ok=False, **kwargs):
1015+
super().__init__(plotly_name=plotly_name,
1016+
parent_name=parent_name, **kwargs)
9931017
self.values = values
9941018
self.array_ok = array_ok
9951019

@@ -1023,8 +1047,10 @@ class InfoArrayValidator(BaseValidator):
10231047
]
10241048
}
10251049
"""
1026-
def __init__(self, plotly_name, parent_name, items, free_length=None, **_):
1027-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
1050+
def __init__(self, plotly_name, parent_name,
1051+
items, free_length=None, **kwargs):
1052+
super().__init__(plotly_name=plotly_name,
1053+
parent_name=parent_name, **kwargs)
10281054
self.items = items
10291055

10301056
self.item_validators = []
@@ -1093,8 +1119,9 @@ class ImageUriValidator(BaseValidator):
10931119
except ModuleNotFoundError:
10941120
pass
10951121

1096-
def __init__(self, plotly_name, parent_name, **_):
1097-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
1122+
def __init__(self, plotly_name, parent_name, **kwargs):
1123+
super().__init__(plotly_name=plotly_name,
1124+
parent_name=parent_name, **kwargs)
10981125

10991126
def description(self):
11001127

@@ -1133,11 +1160,13 @@ def validate_coerce(self, v):
11331160

11341161

11351162
class CompoundValidator(BaseValidator):
1136-
def __init__(self, plotly_name, parent_name, data_class, data_docs):
1137-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
1163+
def __init__(self, plotly_name, parent_name,
1164+
data_class_str, data_docs, **kwargs):
1165+
super().__init__(plotly_name=plotly_name,
1166+
parent_name=parent_name, **kwargs)
11381167

11391168
# Save element class string
1140-
self.data_class_str = data_class
1169+
self.data_class_str = data_class_str
11411170
self._data_class = None
11421171
self.data_docs = data_docs
11431172
self.module_str = CompoundValidator.compute_graph_obj_module_str(
@@ -1215,14 +1244,16 @@ def validate_coerce(self, v):
12151244

12161245

12171246
class CompoundArrayValidator(BaseValidator):
1218-
def __init__(self, plotly_name, parent_name, element_class, element_docs):
1219-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
1247+
def __init__(self, plotly_name, parent_name,
1248+
data_class_str, data_docs, **kwargs):
1249+
super().__init__(plotly_name=plotly_name,
1250+
parent_name=parent_name, **kwargs)
12201251

12211252
# Save element class string
1222-
self.data_class_str = element_class
1253+
self.data_class_str = data_class_str
12231254
self._data_class = None
12241255

1225-
self.data_docs = element_docs
1256+
self.data_docs = data_docs
12261257
self.module_str = CompoundValidator.compute_graph_obj_module_str(
12271258
self.data_class_str, parent_name)
12281259

@@ -1283,8 +1314,9 @@ def validate_coerce(self, v):
12831314

12841315

12851316
class BaseDataValidator(BaseValidator):
1286-
def __init__(self, class_map, plotly_name, parent_name):
1287-
super().__init__(plotly_name=plotly_name, parent_name=parent_name)
1317+
def __init__(self, class_map, plotly_name, parent_name, **kwargs):
1318+
super().__init__(plotly_name=plotly_name,
1319+
parent_name=parent_name, **kwargs)
12881320
self.class_strs_map = class_map
12891321
self._class_map = None
12901322

0 commit comments

Comments
 (0)