Popular recipes tagged "arguments"http://code.activestate.com/recipes/tags/arguments/2016-04-15T13:25:20-07:00ActiveState Code RecipesPython2 keyword-only argument emulation as a decorator. Python3 compatible. (Python)
2016-04-15T13:25:20-07:00István Pásztorhttp://code.activestate.com/recipes/users/4189380/http://code.activestate.com/recipes/580639-python2-keyword-only-argument-emulation-as-a-decor/
<p style="color: grey">
Python
recipe 580639
by <a href="/recipes/users/4189380/">István Pásztor</a>
(<a href="/recipes/tags/args/">args</a>, <a href="/recipes/tags/arguments/">arguments</a>, <a href="/recipes/tags/keyword/">keyword</a>, <a href="/recipes/tags/keyword_only/">keyword_only</a>, <a href="/recipes/tags/kwonly/">kwonly</a>, <a href="/recipes/tags/only/">only</a>, <a href="/recipes/tags/python2/">python2</a>).
Revision 4.
</p>
<p>Provides a very simple decorator (~40 lines of code) that can turn some or all of your default arguments into keyword-only arguments. You select one of your default arguments by name and the decorator turn this argument along with all default arguments on its right side into keyword only arguments. Check the docstring of the decorator or visit the github/pypi page for detailed documentation:</p>
<ul>
<li><a href="https://github.com/pasztorpisti/kwonly-args" rel="nofollow">https://github.com/pasztorpisti/kwonly-args</a></li>
<li><a href="https://pypi.python.org/pypi/kwonly-args" rel="nofollow">https://pypi.python.org/pypi/kwonly-args</a></li>
</ul>
<p><code>$ pip install kwonly-args</code></p>
Decorator for defining functions with keyword-only arguments (Python)
2015-07-10T15:25:04-07:00Oscar Byrnehttp://code.activestate.com/recipes/users/4192487/http://code.activestate.com/recipes/579079-decorator-for-defining-functions-with-keyword-only/
<p style="color: grey">
Python
recipe 579079
by <a href="/recipes/users/4192487/">Oscar Byrne</a>
(<a href="/recipes/tags/arguments/">arguments</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/keyword/">keyword</a>, <a href="/recipes/tags/metadecorator/">metadecorator</a>, <a href="/recipes/tags/positional/">positional</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/python3/">python3</a>).
Revision 2.
</p>
<p>Python2.x implementation of python3's keyword-only arguments (aka arguments that must be specified as keywords, and are not automatically filled in by positional arguments - see PEP 3102).</p>
Keyword-only arguments in Python 2.x (Python)
2015-09-22T18:16:40-07:00Carahttp://code.activestate.com/recipes/users/4191397/http://code.activestate.com/recipes/578993-keyword-only-arguments-in-python-2x/
<p style="color: grey">
Python
recipe 578993
by <a href="/recipes/users/4191397/">Cara</a>
(<a href="/recipes/tags/arguments/">arguments</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/keyword/">keyword</a>, <a href="/recipes/tags/keyword_only/">keyword_only</a>).
Revision 10.
</p>
<p>This is a decorator that makes some of a function's or method's arguments into keyword-only arguments. As much as it possible, it emulates the Python 3 handling of keyword-only arguments, including messages for TypeErrors. It's compatible with Python 3 so it can be used in code bases that support both versions.</p>