-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Closed
Description
I had a quick discussion with @NicolasHug following the discussion of keyword only arguments on the mailing list.
That should be possible to deprecate the use of positional arguments via a decorator, so that
def myfunction(a=1, b=2, c=3):
return a + b + cwill become
def myfunction(*, a=1, b=2, c=3):
return a + b + cbut will not break, but raise a deprecation warning if used with positional arguments.
Might look like:
from warnings import warn
from functools import wraps
def warn_args_wrapper(f):
@wraps(f)
def new_f(*args, **kwargs):
if args:
warn(DeprecationWarning("got args {}, you should use keyword args!".format(args)))
return f(*args, **kwargs)
return new_f
@warn_args_wrapper
def f(a=1, b=2, c=3):
return a + b + cWe would need to put that decorator around all __init__ definitions (at least).
It's a big magic and I'm not sure how well it plays with sphinx.
This RFC is to float the idea and discuss whether it's worth writing a SLEP / doing a prototype.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels