@@ -489,7 +489,7 @@ def __setitem__(self, prop, value):
489489 # ----------------------
490490 # e.g. ('foo', 1)
491491 else :
492- err = _check_path_in_prop_tree (self , orig_prop )
492+ err = _check_path_in_prop_tree (self , orig_prop , error_cast = ValueError )
493493 if err is not None :
494494 raise err
495495 res = self
@@ -3456,7 +3456,7 @@ def _perform_update(plotly_obj, update_obj, overwrite=False):
34563456 # This should be valid even if xaxis2 hasn't been initialized:
34573457 # >>> layout.update(xaxis2={'title': 'xaxis 2'})
34583458 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 )
34603460 if err is not None :
34613461 if isinstance (plotly_obj , BaseLayoutType ):
34623462 # try _subplot_re_match
@@ -3672,7 +3672,7 @@ def _process_kwargs(self, **kwargs):
36723672 """
36733673 invalid_kwargs = {}
36743674 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 )
36763676 if err is None :
36773677 # e.g. underscore kwargs like marker_line_color
36783678 self [k ] = v
@@ -4007,7 +4007,9 @@ def __getitem__(self, prop):
40074007 # Unwrap scalar tuple
40084008 prop = prop [0 ]
40094009 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+ )
40114013
40124014 validator = self ._get_validator (prop )
40134015
@@ -4145,7 +4147,7 @@ def __setitem__(self, prop, value):
41454147
41464148 if self ._validate :
41474149 if prop not in self ._valid_props :
4148- self ._raise_on_invalid_property_error (prop )
4150+ self ._raise_on_invalid_property_error ()( prop )
41494151
41504152 # ### Get validator for this property ###
41514153 validator = self ._get_validator (prop )
@@ -4219,7 +4221,7 @@ def __setattr__(self, prop, value):
42194221 super (BasePlotlyType , self ).__setattr__ (prop , value )
42204222 else :
42214223 # Raise error on unknown public properties
4222- self ._raise_on_invalid_property_error (prop )
4224+ self ._raise_on_invalid_property_error ()( prop )
42234225
42244226 def __iter__ (self ):
42254227 """
@@ -4328,10 +4330,11 @@ def __repr__(self):
43284330
43294331 return repr_str
43304332
4331- def _raise_on_invalid_property_error (self , * args ):
4333+ def _raise_on_invalid_property_error (self , _error_to_raise = None ):
43324334 """
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.
43354338
43364339 Parameters
43374340 ----------
@@ -4341,37 +4344,45 @@ def _raise_on_invalid_property_error(self, *args):
43414344
43424345 Raises
43434346 ------
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
43554351
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+ )
43604383 )
4361- else :
4362- full_obj_name = module_root + self .__class__ .__name__
43634384
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
43754386
43764387 def update (self , dict1 = None , overwrite = False , ** kwargs ):
43774388 """
0 commit comments