Description
Problem
I am in the process to write a library that uses the matplotlib library for its graphics needs. As such, most of "our" graphics functions are wrappers around existing matplotlib functions such as tripcolor, tricontour… A typical function of ours would be:
def fun_name_altered(lib_objects, **kwargs):
args = prepare_args(lib_objects, **kwargs)
plt.fun_name(*args, **kwargs)
In this case the kwargs
dictionnary may contain keywords aimed at the prepare_args
process and keywords aimed at controlling the plotting. At the moment, prepare_args
removes keywords from the dictionnary when used so that in principle, when kwargs
arrive at plt.fun_name
, it should only contain keywords known to plt.fun_name
However, if the user makes a mistake while setting the keyword for OUR part, it is not properly handled by prepare_args
and it does remain inside kwargs
and then is passed to plt.fun_name
which then raises an AttributeError('... got an unexpected keyword argument ...')
.
I would like to be able to try and recover if that happens.
Proposed solution
From the Built-in Exceptions documentation page
The name and obj attributes can be set using keyword-only arguments to the constructor. When set they represent the name of the attribute that was attempted to be accessed and the object that was accessed for said attribute, respectively.
Changed in version 3.10: Added the name and obj attributes
I looked at the matplotlib codebase but I am not an expert programmer so I may be wrong but I think what I would like was that Artist._update_props
set the name
attribute to k
when raising the AttributeError
.
Since I am using Python 3.11 this would allow me to try and remove spurious keywords.