@@ -489,7 +489,7 @@ def __setitem__(self, prop, value):
489
489
# ----------------------
490
490
# e.g. ('foo', 1)
491
491
else :
492
- err = _check_path_in_prop_tree (self , orig_prop )
492
+ err = _check_path_in_prop_tree (self , orig_prop , error_cast = ValueError )
493
493
if err is not None :
494
494
raise err
495
495
res = self
@@ -3456,7 +3456,7 @@ def _perform_update(plotly_obj, update_obj, overwrite=False):
3456
3456
# This should be valid even if xaxis2 hasn't been initialized:
3457
3457
# >>> layout.update(xaxis2={'title': 'xaxis 2'})
3458
3458
for key in update_obj :
3459
- err = _check_path_in_prop_tree (plotly_obj , key )
3459
+ err = _check_path_in_prop_tree (plotly_obj , key , error_cast = ValueError )
3460
3460
if err is not None :
3461
3461
if isinstance (plotly_obj , BaseLayoutType ):
3462
3462
# try _subplot_re_match
@@ -3672,7 +3672,7 @@ def _process_kwargs(self, **kwargs):
3672
3672
"""
3673
3673
invalid_kwargs = {}
3674
3674
for k , v in kwargs .items ():
3675
- err = _check_path_in_prop_tree (self , k )
3675
+ err = _check_path_in_prop_tree (self , k , error_cast = ValueError )
3676
3676
if err is None :
3677
3677
# e.g. underscore kwargs like marker_line_color
3678
3678
self [k ] = v
@@ -4007,7 +4007,9 @@ def __getitem__(self, prop):
4007
4007
# Unwrap scalar tuple
4008
4008
prop = prop [0 ]
4009
4009
if prop not in self ._valid_props :
4010
- self ._raise_on_invalid_property_error (prop )
4010
+ self ._raise_on_invalid_property_error (_error_to_raise = PlotlyKeyError )(
4011
+ prop
4012
+ )
4011
4013
4012
4014
validator = self ._get_validator (prop )
4013
4015
@@ -4145,7 +4147,7 @@ def __setitem__(self, prop, value):
4145
4147
4146
4148
if self ._validate :
4147
4149
if prop not in self ._valid_props :
4148
- self ._raise_on_invalid_property_error (prop )
4150
+ self ._raise_on_invalid_property_error ()( prop )
4149
4151
4150
4152
# ### Get validator for this property ###
4151
4153
validator = self ._get_validator (prop )
@@ -4219,7 +4221,7 @@ def __setattr__(self, prop, value):
4219
4221
super (BasePlotlyType , self ).__setattr__ (prop , value )
4220
4222
else :
4221
4223
# Raise error on unknown public properties
4222
- self ._raise_on_invalid_property_error (prop )
4224
+ self ._raise_on_invalid_property_error ()( prop )
4223
4225
4224
4226
def __iter__ (self ):
4225
4227
"""
@@ -4328,10 +4330,11 @@ def __repr__(self):
4328
4330
4329
4331
return repr_str
4330
4332
4331
- def _raise_on_invalid_property_error (self , * args ):
4333
+ def _raise_on_invalid_property_error (self , _error_to_raise = None ):
4332
4334
"""
4333
- Raise informative exception when invalid property names are
4334
- encountered
4335
+ Returns a function that raises informative exception when invalid
4336
+ property names are encountered. The _error_to_raise argument allows
4337
+ specifying the exception to raise, which is ValueError if None.
4335
4338
4336
4339
Parameters
4337
4340
----------
@@ -4341,37 +4344,45 @@ def _raise_on_invalid_property_error(self, *args):
4341
4344
4342
4345
Raises
4343
4346
------
4344
- PlotlyKeyError
4345
- Always
4346
- """
4347
- invalid_props = args
4348
- if invalid_props :
4349
- if len (invalid_props ) == 1 :
4350
- prop_str = "property"
4351
- invalid_str = repr (invalid_props [0 ])
4352
- else :
4353
- prop_str = "properties"
4354
- invalid_str = repr (invalid_props )
4347
+ ValueError by default, or _error_to_raise if not None
4348
+ """
4349
+ if _error_to_raise is None :
4350
+ _error_to_raise = ValueError
4355
4351
4356
- module_root = "plotly.graph_objs."
4357
- if self ._parent_path_str :
4358
- full_obj_name = (
4359
- module_root + self ._parent_path_str + "." + self .__class__ .__name__
4352
+ def _ret (* args ):
4353
+ invalid_props = args
4354
+ if invalid_props :
4355
+ if len (invalid_props ) == 1 :
4356
+ prop_str = "property"
4357
+ invalid_str = repr (invalid_props [0 ])
4358
+ else :
4359
+ prop_str = "properties"
4360
+ invalid_str = repr (invalid_props )
4361
+
4362
+ module_root = "plotly.graph_objs."
4363
+ if self ._parent_path_str :
4364
+ full_obj_name = (
4365
+ module_root
4366
+ + self ._parent_path_str
4367
+ + "."
4368
+ + self .__class__ .__name__
4369
+ )
4370
+ else :
4371
+ full_obj_name = module_root + self .__class__ .__name__
4372
+
4373
+ raise _error_to_raise (
4374
+ "Invalid {prop_str} specified for object of type "
4375
+ "{full_obj_name}: {invalid_str}\n \n "
4376
+ " Valid properties:\n "
4377
+ "{prop_descriptions}" .format (
4378
+ prop_str = prop_str ,
4379
+ full_obj_name = full_obj_name ,
4380
+ invalid_str = invalid_str ,
4381
+ prop_descriptions = self ._prop_descriptions ,
4382
+ )
4360
4383
)
4361
- else :
4362
- full_obj_name = module_root + self .__class__ .__name__
4363
4384
4364
- raise ValueError (
4365
- "Invalid {prop_str} specified for object of type "
4366
- "{full_obj_name}: {invalid_str}\n \n "
4367
- " Valid properties:\n "
4368
- "{prop_descriptions}" .format (
4369
- prop_str = prop_str ,
4370
- full_obj_name = full_obj_name ,
4371
- invalid_str = invalid_str ,
4372
- prop_descriptions = self ._prop_descriptions ,
4373
- )
4374
- )
4385
+ return _ret
4375
4386
4376
4387
def update (self , dict1 = None , overwrite = False , ** kwargs ):
4377
4388
"""
0 commit comments