RFC deprecate positional arguments
See original GitHub issueI 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 + c
will become
def myfunction(*, a=1, b=2, c=3):
return a + b + c
but 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 + c
We 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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Deprecating Site Local Addresses RFC 3879 - IETF Datatracker
Huitema & Carpenter Standards Track [Page 1] RFC 3879 Deprecating Site Local ... The previous section reviewed the arguments against site-local addresses.
Read more >[Pre-RFC] Keyword arguments - ideas (deprecated)
The design with keyword arguments doesn't have this problem: you can execute the function when the last positional argument is given and ...
Read more >rfc:deprecations_php_7_2 - PHP
This is a draft RFC for multiple deprecations targeting PHP 7.2. The RFC proposes to deprecate the listed functionality in PHP 7.2 and ......
Read more >EmberJS on Twitter: "Deprecate Array Observers Ember's Array ...
Today the Ember Framework team moved 5 RFCs into final comment period. ... Deprecate `` Component Positional Arguments by chancancode · Pull Request...
Read more >tools — Miscellaneous Helper Functions — Pywikibot 7.7.0 ...
A wrapper for a module to deprecate classes or variables of it. Initialise the wrapper. ... The positional arguments are the dictionaries to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is a rough implementation:
For functions:
Calling
hello(1, 3, 5)
will result with a warning:For class methods:
Running
Hello('l2', True)
will result inThe warning can be adjusted.
closed with SLEP 009