positional package

Module contents

class positional.positional(max_positional_args=None, enforcement='except')

Bases: object

A decorator to enforce passing arguments as keywords.

When you have a function that takes a lot of arguments you expect people to pass those arguments as keyword arguments. Python however does not enforce this. In future then if you decide that you want to insert a new argument or rearrange the arguments or transition to using **kwargs you break compatibility with users of your code who (wrongly) gave you 20 positional arguments.

In python 3 there is syntax to prevent this however we are not all in the position where we can write python 3 exclusive code. Positional solves the problem in the mean time across both pythons by enforcing that certain arguments must be past as keyword arguments.

Parameters:max_positional_args – the maixmum number of arguments that can be passed to this function without keyword parameters. Defaults to enforcing that every parameter with a default value must be passed as a keyword argument.

:type max_positional_args int

Parameters:enforcement – defines the way incorrect usage is reported. Currenlty accepts positional.EXCEPT to raise a TypeError or positional.WARN to show a warning. A warning can be useful for applying to functions that are already public as a deprecation notice. Defaults to positional.EXCEPT.
EXCEPT = 'except'
WARN = 'warn'
classmethod classmethod(*args, **kwargs)
classmethod method(max_positional_args=None, enforcement='except')