Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update:</strong></p> <p>I realized that using <code>**kwargs</code> would not solve the problem. If your programmers change function arguments as they wish, one could, for example, change the function to this:</p> <pre><code>def info(foo, **kwargs): </code></pre> <p>and the old code would break again (because now every function call has to include the first argument).</p> <p>It really comes down to what Bryan says.</p> <hr> <blockquote> <p>(...) people might be adding parameters between <code>spacing</code> and <code>collapse</code> (...)</p> </blockquote> <p>In general, when changing functions, new arguments should always go to the end. Otherwise it breaks the code. Should be obvious.<br> If someone changes the function so that the code breaks, this change has to be rejected.<br> (As Bryan says, it is like a contract)</p> <blockquote> <p>(...) sometimes it's not always clear as to what needs to go in.</p> </blockquote> <p>By looking at the signature of the function (i.e <code>def info(object, spacing=10, collapse=1)</code> ) one should immediately see that every argument that has <strong>not</strong> a default value, is mandatory.<br> <strong><em>What</em></strong> the argument is for, should go into the docstring.</p> <hr> <p><em>Old answer (kept for completeness)</em>:</p> <p><strike> This is probably not a good solution:</p> <p>You can define functions this way:</p> <pre><code>def info(**kwargs): ''' Some docstring here describing possible and mandatory arguments. ''' spacing = kwargs.get('spacing', 15) obj = kwargs.get('object', None) if not obj: raise ValueError('object is needed') </code></pre> <p><code>kwargs</code> is a dictionary that contains any keyword argument. You can check whether a mandatory argument is present and if not, raise an exception.</p> <p>The downside is, that it might not be that obvious anymore, which arguments are possible, but with a proper docstring, it should be fine.</p> <p></strike></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload