|
10 | 10 | from copy import deepcopy, copy
|
11 | 11 |
|
12 | 12 | from _plotly_utils.utils import _natural_sort_strings
|
13 |
| -from plotly._validate import validate |
14 | 13 | from .optional_imports import get_module
|
15 | 14 |
|
16 | 15 | # Create Undefined sentinel value
|
@@ -92,6 +91,9 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
|
92 | 91 |
|
93 | 92 | super(BaseFigure, self).__init__()
|
94 | 93 |
|
| 94 | + # Initialize validation |
| 95 | + self._validate = kwargs.pop("_validate", True) |
| 96 | + |
95 | 97 | # Assign layout_plotly to layout
|
96 | 98 | # ------------------------------
|
97 | 99 | # See docstring note for explanation
|
@@ -140,7 +142,9 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
|
140 | 142 | self._data_validator = DataValidator(set_uid=self._set_trace_uid)
|
141 | 143 |
|
142 | 144 | # ### Import traces ###
|
143 |
| - data = self._data_validator.validate_coerce(data, skip_invalid=skip_invalid) |
| 145 | + data = self._data_validator.validate_coerce( |
| 146 | + data, skip_invalid=skip_invalid, _validate=self._validate |
| 147 | + ) |
144 | 148 |
|
145 | 149 | # ### Save tuple of trace objects ###
|
146 | 150 | self._data_objs = data
|
@@ -182,7 +186,7 @@ class is a subclass of both BaseFigure and widgets.DOMWidget.
|
182 | 186 |
|
183 | 187 | # ### Import Layout ###
|
184 | 188 | self._layout_obj = self._layout_validator.validate_coerce(
|
185 |
| - layout, skip_invalid=skip_invalid |
| 189 | + layout, skip_invalid=skip_invalid, _validate=self._validate |
186 | 190 | )
|
187 | 191 |
|
188 | 192 | # ### Import clone of layout properties ###
|
@@ -314,6 +318,8 @@ def __setitem__(self, prop, value):
|
314 | 318 | for p in prop[:-1]:
|
315 | 319 | res = res[p]
|
316 | 320 |
|
| 321 | + res._validate = self._validate |
| 322 | + |
317 | 323 | res[prop[-1]] = value
|
318 | 324 |
|
319 | 325 | def __setattr__(self, prop, value):
|
@@ -1940,10 +1946,13 @@ def _initialize_layout_template(self):
|
1940 | 1946 |
|
1941 | 1947 | if self._layout_obj._props.get("template", None) is None:
|
1942 | 1948 | if pio.templates.default is not None:
|
1943 |
| - with validate(False): |
1944 |
| - # Assume default template is already validated |
| 1949 | + # Assume default template is already validated |
| 1950 | + self._layout_obj._validate = False |
| 1951 | + try: |
1945 | 1952 | template_dict = pio.templates[pio.templates.default]
|
1946 | 1953 | self._layout_obj.template = template_dict
|
| 1954 | + finally: |
| 1955 | + self._layout_obj._validate = self._validate |
1947 | 1956 |
|
1948 | 1957 | @property
|
1949 | 1958 | def layout(self):
|
@@ -3339,6 +3348,8 @@ def __init__(self, plotly_name, **kwargs):
|
3339 | 3348 | # invalid properties will result in an exception
|
3340 | 3349 | self._skip_invalid = False
|
3341 | 3350 |
|
| 3351 | + self._validate = True |
| 3352 | + |
3342 | 3353 | # Validate inputs
|
3343 | 3354 | # ---------------
|
3344 | 3355 | self._process_kwargs(**kwargs)
|
@@ -3378,6 +3389,14 @@ def __init__(self, plotly_name, **kwargs):
|
3378 | 3389 | # ### Backing property for backward compatible _validator property ##
|
3379 | 3390 | self.__validators = None
|
3380 | 3391 |
|
| 3392 | + # @property |
| 3393 | + # def _validate(self): |
| 3394 | + # fig = self.figure |
| 3395 | + # if fig is None: |
| 3396 | + # return True |
| 3397 | + # else: |
| 3398 | + # return fig._validate |
| 3399 | + |
3381 | 3400 | def _get_validator(self, prop):
|
3382 | 3401 | from .validator_cache import ValidatorCache
|
3383 | 3402 |
|
@@ -3425,7 +3444,7 @@ def _process_kwargs(self, **kwargs):
|
3425 | 3444 | if k in self:
|
3426 | 3445 | # e.g. underscore kwargs like marker_line_color
|
3427 | 3446 | self[k] = v
|
3428 |
| - elif not validate._should_validate: |
| 3447 | + elif not self._validate: |
3429 | 3448 | # Set extra property as-is
|
3430 | 3449 | self[k] = v
|
3431 | 3450 | else:
|
@@ -3885,7 +3904,7 @@ def __setitem__(self, prop, value):
|
3885 | 3904 | # ### Unwrap scalar tuple ###
|
3886 | 3905 | prop = prop[0]
|
3887 | 3906 |
|
3888 |
| - if validate._should_validate: |
| 3907 | + if self._validate: |
3889 | 3908 | if prop not in self._valid_props:
|
3890 | 3909 | self._raise_on_invalid_property_error(prop)
|
3891 | 3910 |
|
@@ -3937,6 +3956,8 @@ def __setitem__(self, prop, value):
|
3937 | 3956 | for p in prop[:-1]:
|
3938 | 3957 | res = res[p]
|
3939 | 3958 |
|
| 3959 | + res._validate = self._validate |
| 3960 | + |
3940 | 3961 | res[prop[-1]] = value
|
3941 | 3962 |
|
3942 | 3963 | def __setattr__(self, prop, value):
|
|
0 commit comments