88itself, whereas the generatable content must be edited via templates in
99this file.
1010
11+ This file is python 3 only due to the use of `inspect`
1112"""
1213# We did try to do the wrapping the smart way,
1314# with callable functions and new.function, but could never get the
@@ -209,7 +210,12 @@ def format_value(value):
209210 mappable = ''
210211
211212 # Get argspec of wrapped function
212- args , varargs , varkw , defaults = inspect .getargspec (getattr (Axes , func ))
213+ base_func = getattr (Axes , func )
214+ has_data = 'data' in inspect .signature (base_func ).parameters
215+ work_func = inspect .unwrap (base_func )
216+
217+ args , varargs , varkw , defaults = inspect .getargspec (work_func )
218+
213219 args .pop (0 ) # remove 'self' argument
214220 if defaults is None :
215221 defaults = ()
@@ -222,6 +228,15 @@ def format_value(value):
222228 def_edited .append (val )
223229 defaults = tuple (def_edited )
224230
231+ # Add a data keyword argument if needed (fmt is PLOT_TEMPLATE) and
232+ # possible (if *args is used, we can't just add a data
233+ # argument in front of it since it would gobble one of the
234+ # arguments the user means to pass via *args)
235+ # This needs to be done here so that it goes into call
236+ if not varargs and fmt is PLOT_TEMPLATE and has_data :
237+ args .append ('data' )
238+ defaults = defaults + (None ,)
239+
225240 # How to call the wrapped function
226241 call = []
227242 for i , arg in enumerate (args ):
@@ -230,6 +245,14 @@ def format_value(value):
230245 else :
231246 call .append ('%s=%s' % (arg , arg ))
232247
248+ # remove the data keyword as it was needed above to go into the
249+ # call but should go after `hold` in the signature.
250+ # This is janky as all get out, but hopefully boilerplate will
251+ # be retired soon.
252+ if not varargs and fmt is PLOT_TEMPLATE and has_data :
253+ args .pop ()
254+ defaults = defaults [:- 1 ]
255+
233256 if varargs is not None :
234257 call .append ('*' + varargs )
235258 if varkw is not None :
@@ -249,6 +272,9 @@ def format_value(value):
249272 elif fmt is PLOT_TEMPLATE :
250273 args .append ('hold' )
251274 defaults = defaults + (None ,)
275+ if has_data :
276+ args .append ('data' )
277+ defaults = defaults + (None ,)
252278 sethold = ''
253279
254280 # Now we can build the argspec for defining the wrapper
0 commit comments