Skip to content

Commit 6b39b47

Browse files
committed
Add _validators property for backward compatibility
1 parent 288531d commit 6b39b47

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

packages/python/plotly/plotly/basedatatypes.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,11 +3019,47 @@ def __init__(self, plotly_name, **kwargs):
30193019
# properties is modified
30203020
self._change_callbacks = {}
30213021

3022+
# ### Backing property for backward compatible _validator property ##
3023+
self.__validators = None
3024+
30223025
def _get_validator(self, prop):
30233026
from .validator_cache import ValidatorCache
30243027

30253028
return ValidatorCache.get_validator(self._path_str, prop)
30263029

3030+
@property
3031+
def _validators(self):
3032+
"""
3033+
Validators used to stored in a private _validators property. This was
3034+
eliminated when we switched to building validators on demand using the
3035+
_get_validator method.
3036+
3037+
This property returns a simple object that
3038+
3039+
Returns
3040+
-------
3041+
dict-like interface for accessing the object's validators
3042+
"""
3043+
obj = self
3044+
if self.__validators is None:
3045+
class ValidatorCompat(object):
3046+
def __getitem__(self, item):
3047+
return obj._get_validator(item)
3048+
3049+
def __contains__(self, item):
3050+
return obj.__contains__(item)
3051+
3052+
def __iter__(self):
3053+
return iter(obj)
3054+
3055+
def items(self):
3056+
return [(k, self[k]) for k in self]
3057+
3058+
self.__validators = ValidatorCompat()
3059+
3060+
return self.__validators
3061+
3062+
30273063
def _process_kwargs(self, **kwargs):
30283064
"""
30293065
Process any extra kwargs that are not predefined as constructor params

0 commit comments

Comments
 (0)