Skip to content

Decorator implementing keyword-only arguments in Python 2.x. Compatible with 3.x code.

License

Notifications You must be signed in to change notification settings

ceridwen/keyword_only_args

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Synopsis

Decorator implementing keyword-only arguments in Python 2.x. Compatible with 3.x code.

Code Example

Call the decorator with the names of the arguments to make keyword-only as strings:

@keyword_only_args('c')
def f(a, b, c='c', d='d', *args, **kws):

This will make it so that f() accepts c only as a keyword.

To make a keyword-only argument without a default value, assign a positional argument as keyword-only:

@keyword_only_args('b', 'c')
def f(a, b, c='c', d='d', *args, **kws):

This will make b and c keyword-only, with no default for b.

When called without arguments, the decorator will make all arguments with default values keyword-only:

@keyword_only_args()
def f(a, b, c='c', d='d', *args, **kws):

This will make c and d keyword-only.

License

MIT.

About

Decorator implementing keyword-only arguments in Python 2.x. Compatible with 3.x code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages