Skip to content

Commit

Permalink
Added a table of @kwoargs alternatives.
Browse files Browse the repository at this point in the history
  • Loading branch information
epsy committed May 10, 2015
1 parent fb34e87 commit 82a3cac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ Here, :func:`@autokwoargs <sigtools.modifiers.autokwoargs>` turns all
parameters with defaults into keyword-only parameters. Clize then treats it as
an option instead of a positional parameter.

.. seealso:: :ref:`named param py2`

.. note::
Since Python does not have syntax for specifying keyword-only parameters
until Python 3, we will use decorators from the :mod:`sigtools.modifiers`
Expand Down
27 changes: 26 additions & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,32 @@ pass them as strings in the parameter's annotation:
$ python named.py --param value
par value
All parameter names are converted by removing any underscores (``_``) off the extremities of the string and replacing the remaining ones with dashes (``-``).
All parameter names are converted by removing any underscores (``_``) off the
extremities of the string and replacing the remaining ones with dashes (``-``).


.. _named param py2:

Python 2 support for named parameters
.....................................

Python 2 has no keyword-only parameters. To fill that gap, you can use the
decorators from `sigtools.modifiers` to emulate them.

.. code-block:: python
@DECORATOR
def func(ab, cd, de=None, fg=None, hi=None):
...
=================================== ===================================
``@DECORATOR`` Parameters that become keyword-only
=================================== ===================================
``@kwoargs('cd', 'fg')`` ``cd`` and ``fg``
``@kwoargs(start='fg')`` ``fg`` and all following parameters
``@autokwoargs`` All parameters with defaut values
``@autokwoargs(exceptions=['fg'])`` Same, except for ``fg``
=================================== ===================================


.. _option param:
Expand Down

0 comments on commit 82a3cac

Please sign in to comment.