Hello,

On Tue, 26 May 2020 07:34:32 +1000
Chris Angelico <ros...@gmail.com> wrote:

[]

> > _complex_mutable_default = MyObj(a = 1, b = 2, c = 3, d = 4, e = 5,
> > f = 6, g = 7, h = 8, i = 9, j = 10)
> >
> > def func(x := _complex_mutable_default): ...
> >
> > Above, _complex_mutable_default is NOT immutable-- it is mutable.
> >  
> 
> I don't see how this is going to be any different from anything else.
> If you do the same thing using the current "=object()" idiom, and you
> break out the complex default into a global, then obviously you're
> asking for it to be evaluated only once. Surely that shouldn't be at
> all surprising.

The more worrying sounds the idea to have a special evaluation context
for specially marked default arguments. Just imagine - *everywhere* (#1)
in the language the evaluation is eager, while for specially marked
default arguments it's deferred. Which leads to the situation that:

        def foo(x := a + b)

vs

        c = a + b
        def foo(x := c)

can lead to different results.

I'd suggest that people should love "explicit is better than implicit"
principle of the language.

And those who don't, aren't going to be satisfied by minor bend-in's
like that - they will want more (while even small things like that will
be confusing for all the rest). I'd suggest they're looking for generic
macros facility instead, which in this particular case will allow them
to wrap default argument expression in lambda, then insert if's in the
body to call that lambda if the argument value is not provided.

So, just revive https://www.python.org/dev/peps/pep-0511/ and rock on.
(And that PEP is just a convenience, you can do everything needed for
that right away, albeit in a nicely tangled manner.)


#1: Except for https://www.python.org/dev/peps/pep-0563 , but
annotations (and results of their evaluation) are not the part of the
baseline language semantics (baseline == as implemented by CPython).

> 
> ChrisA

[]

-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SS44HNNZGGJBFCPORUS46C7ZEGOSUG5I/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to