[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Stephen J. Turnbull
Brendan Barnwell writes: > As I've said before, the problem is that the benefit of this > feature is too small to justify this large change to the status quo. I don't disagree with this (but the whole thing is a YAGNI fvo "you" = "me" so I'm uncomfortable agreeing as long "as x = x or defa

[Python-ideas] PEP 671 late-bound defaults implementation

2021-10-31 Thread Steven D'Aprano
I have a suggestion for the implementation. I think that Chris' current approach is to compile the late-bound defaults in the function body. So if we have a function like this: def func(a, b=early_expression, @c=late_expression): block the function code looks like this (after compil

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Steven D'Aprano
On Sun, Oct 31, 2021 at 02:24:10PM +1100, Chris Angelico wrote: > That last part is the most important here: it has to be evaluated *in > the context of the function*. That's the only way for things like "def > f(a, n=len(a)):" to be possible. Agreed so far. > Every piece of code in Python is e

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Steven D'Aprano
On Sun, Oct 31, 2021 at 03:10:56PM +1100, Chris Angelico wrote: > (Side point: The current reference implementation allows assignment > expressions inside default argument expressions, mainly because I > didn't go to the effort of blocking them. But if you ever ACTUALLY do > this, then. *wat*)

[Python-ideas] Re: PEP 671 proof-of-concept: A less invasive implementation

2021-10-31 Thread Jonathan Fine
Hi I've just had a brainwave that may give an even less invasive implementation of PEP 671. It relies on every function having a dict, as provided by https://www.python.org/dev/peps/pep-0232/. Consider: def fn(a, b, c): pass fn.__wibble__ = 123 fn.__wibble__ # Give 123, of course. No

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Steven D'Aprano
On Tue, Oct 26, 2021 at 08:59:51AM +0100, Rob Cliffe via Python-ideas wrote: > And I don't understand what point you're making here.  Yes, the walrus > operator can appear in various places, how is that relevant? You could write >     def f(a := (b := c)): > which might be a tad confusing but wou

[Python-ideas] Re: PEP 671 late-bound defaults implementation

2021-10-31 Thread Steven D'Aprano
On Sun, Oct 31, 2021 at 06:22:09PM +1100, Steven D'Aprano wrote: [snip] > Benefits: If I have understood Chris correctly, there's another benefit. Replacing the late bound defaults in the function object will no longer be a misleading no-op that confuses introspection tools such as inspect.sig

[Python-ideas] Re: Deferred evaluation (was: PEP 671: Syntax for late-bound function argument defaults)

2021-10-31 Thread Sven R. Kunze
Actually, the "defer:"-syntax is really readable and searchable compared to the cryptic comparison operator used in the proposal. Just thinking towards "googleability". Furthermore, the concept is even more general than parameter definition of functions and methods. I guess a lot of people hav

[Python-ideas] Re: PEP 671 proof-of-concept: A less invasive implementation

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 7:01 PM Jonathan Fine wrote: > > Hi > > I've just had a brainwave that may give an even less invasive implementation > of PEP 671. It relies on every function having a dict, as provided by > https://www.python.org/dev/peps/pep-0232/. > > Consider: > def fn(a, b, c): p

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 6:36 PM Steven D'Aprano wrote: > > On Sun, Oct 31, 2021 at 02:24:10PM +1100, Chris Angelico wrote: > > > That last part is the most important here: it has to be evaluated *in > > the context of the function*. That's the only way for things like "def > > f(a, n=len(a)):" to

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 6:50 PM Steven D'Aprano wrote: > > On Sun, Oct 31, 2021 at 03:10:56PM +1100, Chris Angelico wrote: > > > (Side point: The current reference implementation allows assignment > > expressions inside default argument expressions, mainly because I > > didn't go to the effort of

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 7:10 PM Steven D'Aprano wrote: > > On Tue, Oct 26, 2021 at 08:59:51AM +0100, Rob Cliffe via Python-ideas wrote: > > > And I don't understand what point you're making here. Yes, the walrus > > operator can appear in various places, how is that relevant? You could write > >

[Python-ideas] Re: Deferred evaluation (was: PEP 671: Syntax for late-bound function argument defaults)

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 9:24 PM Sven R. Kunze wrote: > > Actually, the "defer:"-syntax is really readable and searchable compared to > the cryptic comparison operator used in the proposal. Just thinking towards > "googleability". > Google's smarter than that. I've searched for symbols before an

[Python-ideas] Re: PEP 671 proof-of-concept: A less invasive implementation

2021-10-31 Thread Jonathan Fine
Hi Chris Again you ask good questions. Q: How to find the bare string '#wibble'? It's optimised out during compilation. A: Very good. I didn't know that. For current Python we'll have to use a different marker. For future Python we could change the compiler so that it directly sets fn.__wibble__

[Python-ideas] Re: PEP 671 late-bound defaults implementation

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 6:25 PM Steven D'Aprano wrote: > > I have a suggestion for the implementation. > > I think that Chris' current approach is to compile the late-bound > defaults in the function body. So if we have a function like this: > > def func(a, b=early_expression, @c=late_expressi

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 5:25 PM Chris Angelico wrote: > I don't think this is a major problem. It's no worse than other things > you can mess with, and if you do that sort of thing, you get only what > you asked for; there's no way you can get a segfault or even an > exception, as long as you use

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Eric V. Smith
On 10/30/2021 10:08 PM, Christopher Barker wrote: I'm a bit confused as to why folks are making pronouncements about their support for this PEP before it's even finished, but, oh well. I think it's safe to say people are opposed to the PEP as it current stands, not in it's final, as yet unseen,

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 11:47 PM Eric V. Smith wrote: > > On 10/30/2021 10:08 PM, Christopher Barker wrote: > > I'm a bit confused as to why folks are making pronouncements about > > their support for this PEP before it's even finished, but, oh well. > I think it's safe to say people are opposed t

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Paul Moore
On Sun, 31 Oct 2021 at 12:45, Eric V. Smith wrote: > > I think it's safe to say people are opposed to the PEP as it current > stands, not in it's final, as yet unseen, shape. But I'm willing to use > other words that "I'm -1 on PEP 671". You can read my opposition as "as > it currently stands, I'm

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Erik Demaine
On Sat, 30 Oct 2021, Erik Demaine wrote: Functions are already a form of deferred evaluation. PEP 671 is an embellishment to this mechanism for some of the code in the function signature to actually get executed within the body scope, *just like the body of the function*. I was thinking abo

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Mon, Nov 1, 2021 at 2:39 AM Erik Demaine wrote: > > On Sat, 30 Oct 2021, Erik Demaine wrote: > > > Functions are already a form of deferred evaluation. PEP 671 is an > > embellishment to this mechanism for some of the code in the function > > signature to actually get executed within the body

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread David Mertz, Ph.D.
On Sun, Oct 31, 2021, 8:59 AM Chris Angelico > def foo1(a=>[1,2,3], b=>len(a)): > a.append(4) > print(b) > > And what is the correct behaviour here? > > def foo2(a=defer [1,2,3], b=defer len(a)): > a.append(4) > print(b) > This is a nice example. I agree they are different in the

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Mon, Nov 1, 2021 at 2:59 AM David Mertz, Ph.D. wrote: > > On Sun, Oct 31, 2021, 8:59 AM Chris Angelico >> >> def foo1(a=>[1,2,3], b=>len(a)): >> a.append(4) >> print(b) >> >> And what is the correct behaviour here? >> >> def foo2(a=defer [1,2,3], b=defer len(a)): >> a.append(4) >>

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Rob Cliffe via Python-ideas
On 31/10/2021 08:05, Steven D'Aprano wrote: On Tue, Oct 26, 2021 at 08:59:51AM +0100, Rob Cliffe via Python-ideas wrote: And I don't understand what point you're making here.  Yes, the walrus operator can appear in various places, how is that relevant? You could write     def f(a := (b := c)

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Erik Demaine
On Mon, 1 Nov 2021, Chris Angelico wrote: This is incompatible with the existing __get__ method, so it should get a different name. Also, functions have a __get__ method, so you definitely don't want to have everything that takes a callback run into this. Let's say it's __delayed__ instead. Ri

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Brendan Barnwell
On 2021-10-31 05:57, Chris Angelico wrote: Deferred expressions are not the same as late-bound argument defaults. You keep saying this, but I still don't get the point. Descriptors are not the same as properties, but we can implement properties with descriptors. Decorators are not the same

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Mon, Nov 1, 2021 at 5:03 AM Brendan Barnwell wrote: > > On 2021-10-31 05:57, Chris Angelico wrote: > > Deferred expressions are not the same as late-bound argument defaults. > > You keep saying this, but I still don't get the point. Descriptors > are > not the same as properties, but

[Python-ideas] Re: Deferred evaluation (was: PEP 671: Syntax for late-bound function argument defaults)

2021-10-31 Thread Sven R. Kunze
On 31.10.21 12:34, Chris Angelico wrote: Google's smarter than that. I've searched for symbols before and found plenty of good results. For instance, I can search for information about the @ sign before a function, or independently, for a @ b, and get information about decorators or matrix multip

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Rob Cliffe via Python-ideas
On 27/10/2021 08:56, Chris Angelico wrote: On Wed, Oct 27, 2021 at 5:14 PM Brendan Barnwell wrote: But I still think it's worth noticing that the new syntax is not going to add a "full dimension". It is only going to be useful for VERY SIMPLE late-bound default values. If the late-bound d

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Rob Cliffe via Python-ideas
On 31/10/2021 18:00, Brendan Barnwell wrote: On 2021-10-31 05:57, Chris Angelico wrote: Deferred expressions are not the same as late-bound argument defaults. You keep saying this, but I still don't get the point. Descriptors are not the same as properties, but we can implement properti

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread David Mertz, Ph.D.
On Sun, Oct 31, 2021, 5:39 PM Rob Cliffe via Python-ideas > PEP 671 will be USEFUL to Python programmers. We want it! (When do we > want it? Now!) > This feels dishonest. I believe I qualify as a Python programmer. I started using Python 1.4 in 1998. The large majority of my work life since th

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Brendan Barnwell
On 2021-10-31 14:38, Rob Cliffe via Python-ideas wrote: Wonderful! +1,000,000. So are you going to write a PEP explaining exactly how you propose to implement deferred expressions and how they would be used? And perhaps provide a reference implementation? Then we can see how it works, and how i

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Mon, Nov 1, 2021 at 8:56 AM David Mertz, Ph.D. wrote: > I am not on the SC, so indeed I won't make the decision. But I *will* > continue to teach Python. New syntax adds a burden to learners, and it should > not be introduced without sufficient benefit to merit that burden. This > proposal d

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Rob Cliffe via Python-ideas
On 31/10/2021 21:54, David Mertz, Ph.D. wrote: On Sun, Oct 31, 2021, 5:39 PM Rob Cliffe via Python-ideas PEP 671 will be USEFUL to Python programmers.  We want it!  (When do we want it?  Now!) This feels dishonest. I believe I qualify as a Python programmer. I started using Python 1

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread David Mertz, Ph.D.
On Sun, Oct 31, 2021, 6:11 PM Chris Angelico > On Mon, Nov 1, 2021 at 8:56 AM David Mertz, Ph.D. > wrote: > > I am not on the SC, so indeed I won't make the decision. But I *will* > continue to teach Python. New syntax adds a burden to learners, and it > should not be introduced without sufficien

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Brendan Barnwell
On 2021-10-31 15:08, Chris Angelico wrote: On Mon, Nov 1, 2021 at 8:56 AM David Mertz, Ph.D. wrote: I am not on the SC, so indeed I won't make the decision. But I *will* continue to teach Python. New syntax adds a burden to learners, and it should not be introduced without sufficient benefit to

[Python-ideas] Re: Deferred evaluation (was: PEP 671: Syntax for late-bound function argument defaults)

2021-10-31 Thread Steven D'Aprano
On Sun, Oct 31, 2021 at 09:20:32PM +0100, Sven R. Kunze wrote: > People on the threads said that they simply want to initialize an empty > list [] by a desire to avoid the None scheme. > > I would rather solve those kind of issues than help to squeeze > complicated logic into default parameters

[Python-ideas] Re: Deferred evaluation (was: PEP 671: Syntax for late-bound function argument defaults)

2021-10-31 Thread Chris Angelico
On Mon, Nov 1, 2021 at 11:26 AM Steven D'Aprano wrote: > What sort of testing and maintenance perspective are you referring to? > Testing and maintenance of the Python interpreter? Or your own code? > > If it is your own code then this proposal will have no effect on your > testing and maintenance

[Python-ideas] Re: PEP 671 proof-of-concept: A less invasive implementation

2021-10-31 Thread Chris Angelico
On Sun, Oct 31, 2021 at 4:50 AM Eric V. Smith wrote: > > On 10/30/2021 10:40 AM, Chris Angelico wrote: > > And, seeing something in help(fn) largely necessitates that the source > > code be retained. I don't know of any other way to do it. If you say > > that the default argument is "len(a)", then

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Greg Ewing
On 1/11/21 4:59 am, David Mertz, Ph.D. wrote:     b = b I don't want to live in a universe where this could be anything other than a no-op in Python. -- Greg ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to py

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-10-31 Thread Chris Angelico
On Mon, Nov 1, 2021 at 5:15 PM Greg Ewing wrote: > > On 1/11/21 4:59 am, David Mertz, Ph.D. wrote: > > b = b > > I don't want to live in a universe where this could be anything > other than a no-op in Python. > Be careful what you say: there are some technicalities. If you mean that it won't