[Python-Dev] PEP 457: Syntax For Positional-Only Parameters (original) (raw)
Mark Shannon mark at hotpy.org
Wed Oct 9 22:46:00 CEST 2013
- Previous message: [Python-Dev] PEP 457: Syntax For Positional-Only Parameters
- Next message: [Python-Dev] PEP 457: Syntax For Positional-Only Parameters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 09/10/13 00:33, Larry Hastings wrote:
I've contributed a new PEP to humanity. I include the RST for your reading pleasure below, but you can also read it online here: http://www.python.org/dev/peps/pep-0457/
Overall I'm in favour.
As a motivation for positional only parameters, consider:
Python 3.2:
from decimal import Decimal d = Decimal(4) d.add(other=d) Decimal('8')
Python 3.3:
from decimal import Decimal d = Decimal(4) d.add(other=d) Traceback (most recent call last): File "", line 1, in TypeError: wrapper add doesn't take keyword arguments
[snip]
The obvious solution: add a new singleton constant to Python that is passed in when a parameter is not mapped to an argument. I propose that the value be called called
undefined
, and be a singleton of a special class calledUndefined
. If a positional-only parameter did not receive an argument when called, its value would be set toundefined
.
There is no need to create an "undefined" value. Rather than define a parameter by assigning a fake value, just don't define it. We already do this for non-parameter locals and it could be extended to parameters.
'range' would be defined thus:
def range([start,] stop, [step], /): try: start except UnboundLocalError: start = 0 try: step except UnboundLocalError: step = 1 ...
Cheers, Mark.
- Previous message: [Python-Dev] PEP 457: Syntax For Positional-Only Parameters
- Next message: [Python-Dev] PEP 457: Syntax For Positional-Only Parameters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]