RETIRED, further work has moved to Debian project infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Morgan Fainberg 6cca228838 Merge pull request #21 from morganfainberg/morganfainberg-support-py35 3 years ago
doc Merge branch 'jamielennox-readme' 4 years ago
positional Fix to preserve argspec 3 years ago
.coveragerc Add tests and support files. 4 years ago
.gitignore Stop ignoring doc/source/api 4 years ago
.testr.conf Add tests and support files. 4 years ago
.travis.yml Update .travis.yml 3 years ago
LICENSE Remove copied copyright 4 years ago
README.rst Fix the python3 demo in README 3 years ago
requirements.txt Update requirements.txt for pbr versions to match 3 years ago
setup.cfg Merge branch 'master' into morganfainberg-support-py35 3 years ago Remove references to gate 4 years ago
test-requirements.txt Merge pull request #4 from jamielennox/no-gate 4 years ago
tox.ini Update tox.ini 3 years ago



A decorator which enforces only some args may be passed positionally.


Build Status

Documentation Status

The Basics

positional provides a decorator which enforces only some args may be passed positionally. The idea and some of the code was taken from the oauth2 client of the google-api client.

The decorator makes it easy to support Python 3 style key-word only parameters. For example, in Python 3 it is possible to write:

All named parameters after * must be a keyword:

To replicate this behaviour with the positional decorator you simply specify how many arguments may be passed positionally.

First to import the decorator we typically use:

Replicating the Example above:

If no default value is provided to a keyword argument, it becomes a required keyword argument:

This must be called with the keyword parameter:

When defining instance or class methods always remember that in python the first positional argument passed is the instance; you will need to account for self and `cls`:

If you would prefer not to account for self and cls you can use the method and classmethod helpers which do not consider the initial positional argument. So the following class is exactly the same as the one above:

If a value isn't provided to the decorator then it will enforce that every variable without a default value will be required to be a kwarg:

This behaviour will work with the positional.method and positional.classmethod helper functions as well:

For compatibility reasons you may wish to not always raise an exception so a WARN mode is available. Rather than raise an exception a warning will be emitted.

Available modes are:

  • positional.EXCEPT - the default, raise an exception.
  • positional.WARN - emit a warning.