[Python-ideas] Positional-only parameters

Frazer McLean frazer at frazermclean.co.uk
Tue Feb 28 17:07:27 EST 2017


On 28 Feb 2017, at 22:17, Victor Stinner wrote:

> I just noticed a module on PyPI to implement this behaviour on Python 
> functions:
>
>    https://pypi.python.org/pypi/positional

Tangential to the main topic, but this module doesn’t enforce 
positional-only
arguments. It allows you enforce keyword-only arguments like on Python 
3:

	>>> from positional import positional
	>>> @positional(1)
	... def replace(old, new):
	...     ...
	...
	>>> replace(old='a', new='b')
	>>> replace('a', 'b')
	Traceback (most recent call last):
	  File "<stdin>", line 1, in <module>
	  File “…/site-packages/positional/__init__.py", line 97, in inner
	    raise TypeError(message)
	TypeError: replace takes at most 1 positional argument (2 given)

Frazer


More information about the Python-ideas mailing list