Morganfainberg support py35
|4 years ago|
|doc||4 years ago|
|positional||4 years ago|
|.coveragerc||4 years ago|
|.gitignore||4 years ago|
|.testr.conf||4 years ago|
|.travis.yml||4 years ago|
|LICENSE||4 years ago|
|README.rst||4 years ago|
|requirements.txt||4 years ago|
|setup.cfg||4 years ago|
|setup.py||4 years ago|
|test-requirements.txt||4 years ago|
|tox.ini||4 years ago|
A decorator which enforces only some args may be passed positionally.
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: