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 "<stdin>", line 1, in <module>
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 called ``Undefined``.
If a positional-only parameter did not receive an argument
when called, its value would be set to ``undefined``.

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.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to