8
8
itself, whereas the generatable content must be edited via templates in
9
9
this file.
10
10
11
+ This file is python 3 only due to the use of `inspect`
11
12
"""
12
13
# We did try to do the wrapping the smart way,
13
14
# with callable functions and new.function, but could never get the
@@ -209,9 +210,12 @@ def format_value(value):
209
210
mappable = ''
210
211
211
212
# Get argspec of wrapped function
212
- work_func = getattr (Axes , func )
213
- if hasattr (work_func , '__wrapped__' ):
214
- work_func = work_func .__wrapped__
213
+ base_func = getattr (Axes , func )
214
+ has_data = 'data' in inspect .signature (base_func ).parameters
215
+ if hasattr (base_func , '__wrapped__' ):
216
+ work_func = base_func .__wrapped__
217
+ else :
218
+ work_func = base_func
215
219
216
220
args , varargs , varkw , defaults = inspect .getargspec (work_func )
217
221
@@ -227,6 +231,15 @@ def format_value(value):
227
231
def_edited .append (val )
228
232
defaults = tuple (def_edited )
229
233
234
+ # Add a data keyword argument if needed (fmt is PLOT_TEMPLATE) and
235
+ # possible (if *args is used, we can't just add a data
236
+ # argument in front of it since it would gobble one of the
237
+ # arguments the user means to pass via *args)
238
+ # This needs to be done here so that it goes into call
239
+ if not varargs and fmt is PLOT_TEMPLATE and has_data :
240
+ args .append ('data' )
241
+ defaults = defaults + (None ,)
242
+
230
243
# How to call the wrapped function
231
244
call = []
232
245
for i , arg in enumerate (args ):
@@ -235,6 +248,14 @@ def format_value(value):
235
248
else :
236
249
call .append ('%s=%s' % (arg , arg ))
237
250
251
+ # remove the data keyword as it was needed above to go into the
252
+ # call but should go after `hold` in the signature.
253
+ # This is janky as all get out, but hopefully boilerplate will
254
+ # be retired soon.
255
+ if not varargs and fmt is PLOT_TEMPLATE and has_data :
256
+ args .pop ()
257
+ defaults = defaults [:- 1 ]
258
+
238
259
if varargs is not None :
239
260
call .append ('*' + varargs )
240
261
if varkw is not None :
@@ -254,6 +275,9 @@ def format_value(value):
254
275
elif fmt is PLOT_TEMPLATE :
255
276
args .append ('hold' )
256
277
defaults = defaults + (None ,)
278
+ if has_data :
279
+ args .append ('data' )
280
+ defaults = defaults + (None ,)
257
281
sethold = ''
258
282
259
283
# Now we can build the argspec for defining the wrapper
0 commit comments