Forced naming of parameters in python

Posted by Mark Mayo on Stack Overflow See other posts from Stack Overflow or by Mark Mayo
Published on 2010-06-03T11:00:54Z Indexed on 2010/06/03 11:04 UTC
Read the original article Hit count: 207

In python you may have a function definition:

def info(object, spacing=10, collapse=1)

which could be called in any of the following ways:

info(odbchelper)                    
info(odbchelper, 12)                
info(odbchelper, collapse=0)        
info(spacing=15, object=odbchelper)

thanks to python's allowing of any-order arguments, so long as they're named.

The problem we're having is as some of our larger functions grow, people might be adding parameters between spacing and collapse, meaning that the wrong values may be going to parameters that aren't named. In addition sometimes it's not always clear as to what needs to go in. We're after a way to force people to name certain parameters - not just a coding standard, but ideally a flag or pydev plugin?

so that in the above 4 examples, only the last would pass the check as all the parameters are named.

Odds are we'll only turn it on for certain functions, but any suggestions as to how to implement this - or if it's even possible would be appreciated.

© Stack Overflow or respective owner

Related posts about python

Related posts about coding-standards