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

2021-11-03 Thread Stephen J. Turnbull
Steven D'Aprano writes: > "Write `arg=default` if you want the default to be evaluated just once, > and `arg=late default` if you want the default to be evaluated each time > it is needed. If you are not sure which one you need, use the > first." Which of course is ambiguous, since the argu

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

2021-11-03 Thread Chris Angelico
On Wed, Nov 3, 2021 at 6:01 PM Stephen J. Turnbull wrote: > > Steven D'Aprano writes: > > > "Write `arg=default` if you want the default to be evaluated just once, > > and `arg=late default` if you want the default to be evaluated each time > > it is needed. If you are not sure which one you ne

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

2021-11-03 Thread Christopher Barker
> But then the question becomes: should we recommend late-binding by > default, with early-binding as an easy optimization? Given the decades of code that is using early binding now, I think it would be a really bad idea not to teach that as the default— folks absolutely need to understand early

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Ethan Furman
One similarity that I don't think has been mentioned yet: - decorator syntax says, "run me later, after this function is built" - late-bound argument syntax says, "run me later, just before each function call" Because both mean "run me later" we can leverage the @ symbol to aid understanding;

[Python-ideas] Re: Beginners accidentally shadow module names due to different expectation of the resolution order for module imports

2021-11-03 Thread Ned Batchelder
On 11/2/21 6:03 AM, Florian Wetschoreck wrote: Hello everyone: The scenario/observation: Beginners sometimes create scripts with the name of a package e.g. pandas.py or seaborn.py in order to test something. There's a previous discussion about preventing importing a file into itself. It's a

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 2:29 AM Ethan Furman wrote: > > One similarity that I don't think has been mentioned yet: > > - decorator syntax says, "run me later, after this function is built" > > - late-bound argument syntax says, "run me later, just before each function > call" Hmm, I more think of

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Ethan Furman
On 11/3/21 9:07 AM, Chris Angelico wrote: > On Thu, Nov 4, 2021 at 2:29 AM Ethan Furman wrote: >> One similarity that I don't think has been mentioned yet: >> >> - decorator syntax says, "run me later, after this function is built" >> >> - late-bound argument syntax says, "run me later, just befo

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Steven D'Aprano
On Thu, Nov 04, 2021 at 03:07:22AM +1100, Chris Angelico wrote: > def func(spam: list = []) -> str: ... > > Which part of that becomes late bound? The name "spam" of course. Without the parameter, nothing gets bound at all. > The [], not the name "list", not the name "spam". The type annotat

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Steven D'Aprano
On Wed, Nov 03, 2021 at 10:25:02AM -0700, Ethan Furman wrote: > Which is horrible. Put the @ at the front: > > - its relation to decorators, and delayed evaluation, is much more clear > - it stands out better to the reader I agree. (Well, I would, wouldn't I? :-) But if people really, really h

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 4:25 AM Ethan Furman wrote: > > On 11/3/21 9:07 AM, Chris Angelico wrote: > > On Thu, Nov 4, 2021 at 2:29 AM Ethan Furman wrote: > > >> One similarity that I don't think has been mentioned yet: > >> > >> - decorator syntax says, "run me later, after this function is buil

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 4:30 AM Steven D'Aprano wrote: > > On Thu, Nov 04, 2021 at 03:07:22AM +1100, Chris Angelico wrote: > > > def func(spam: list = []) -> str: ... > > > > Which part of that becomes late bound? > > The name "spam" of course. Without the parameter, nothing gets bound at > all. T

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 4:38 AM Steven D'Aprano wrote: > > On Wed, Nov 03, 2021 at 10:25:02AM -0700, Ethan Furman wrote: > > > Which is horrible. Put the @ at the front: > > > > - its relation to decorators, and delayed evaluation, is much more clear > > - it stands out better to the reader > > I

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Steven D'Aprano
On Thu, Nov 04, 2021 at 04:36:27AM +1100, Chris Angelico wrote: > You use the name because you can't refer to it other than by name, and > that's fine. But it's the *default* that is different. Not the > parameter. Wait, are you saying that the list display here: parameter=[] is different f

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 4:56 AM Steven D'Aprano wrote: > > On Thu, Nov 04, 2021 at 04:36:27AM +1100, Chris Angelico wrote: > > > You use the name because you can't refer to it other than by name, and > > that's fine. But it's the *default* that is different. Not the > > parameter. > > Wait, are you

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Ethan Furman
On 11/3/21 10:35 AM, Steven D'Aprano wrote: > I suppose that we could even add yet another overloaded meaning on the > asterix: > > # with no default, * keeps the old meaning of collecting > # extra positional values > > *parameter > > # with a default, * triggers late-binding

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

2021-11-03 Thread Stephen J. Turnbull
Chris Angelico writes: > While it's possible to avoid some of those, we can't hold the > language back because *someone who doesn't understand* might > misunderstand. Opposing the proposal wasn't the point of quoting Steve, the point was to provide IMO improved language in case the proposal ge

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Christopher Barker
There’s some conflict about whether it’s the name or the expression that’s different, and thus should be adorned. But it’s neither: it’s the “=“ that’s different— so that’s what should be a different symbol. As for “=>” — I like it now, but if that same symbol is adopted for lambda, it would be h

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread MRAB
On 2021-11-03 18:14, Ethan Furman wrote: On 11/3/21 10:35 AM, Steven D'Aprano wrote: > I suppose that we could even add yet another overloaded meaning on the > asterix: > > # with no default, * keeps the old meaning of collecting > # extra positional values > > *para

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

2021-11-03 Thread Ethan Furman
On 11/3/21 12:13 AM, Chris Angelico wrote: > Python has a strong policy of evaluating things immediately, or being > very clear about when they will be evaluated Putting the marker in the middle of the name binding expression is not "very clear" -- particularly since the advice is "ne spaces ar

[Python-ideas] Re: Beginners accidentally shadow module names due to different expectation of the resolution order for module imports

2021-11-03 Thread Florian Wetschoreck
Hey Ned, Thank you for mentioning the old and related issue. In order to prevent confusion, I want to point out that the primary scenario that I meant is not that the file imports itself but another file in the same directory with the name of a module that is also installed in site-packages. Not

[Python-ideas] Re: Beginners accidentally shadow module names due to different expectation of the resolution order for module imports

2021-11-03 Thread Ethan Furman
On 11/3/21 12:21 PM, Florian Wetschoreck wrote: > In order to prevent confusion, I want to point out that the primary scenario that I meant is not that the file imports > itself but another file in the same directory with the name of a module that is also installed in site-packages. Not > sure

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

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 5:28 AM Stephen J. Turnbull wrote: > > > And that's what happens when you need to be pedantically correct. Not > > particularly useful to a novice, especially with the FUD at the > > end. > > I have no idea what you mean by "that's what happens," except that > apparently

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

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 5:54 AM Ethan Furman wrote: > > On 11/3/21 12:13 AM, Chris Angelico wrote: > > > Python has a strong policy of evaluating things immediately, or being > > very clear about when they will be evaluated > > Putting the marker in the middle of the name binding expression is no

[Python-ideas] Re: Beginners accidentally shadow module names due to different expectation of the resolution order for module imports

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 6:37 AM Ethan Furman wrote: > > On 11/3/21 12:21 PM, Florian Wetschoreck wrote: > > > In order to prevent confusion, I want to point out that the primary > scenario that I meant is not that the file imports > > itself but another file in the same directory with the name o

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

2021-11-03 Thread Ethan Furman
On 11/3/21 2:31 PM, Chris Angelico wrote: > On Thu, Nov 4, 2021 at 5:54 AM Ethan Furman wrote: >> On 11/3/21 12:13 AM, Chris Angelico wrote: >>> Python has a strong policy of evaluating things immediately, or being >>> very clear about when they will be evaluated >> >> Putting the marker in the m

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

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 9:33 AM Ethan Furman wrote: > > On 11/3/21 2:31 PM, Chris Angelico wrote: > > On Thu, Nov 4, 2021 at 5:54 AM Ethan Furman wrote: > >> On 11/3/21 12:13 AM, Chris Angelico wrote: > > >>> Python has a strong policy of evaluating things immediately, or being > >>> very clear

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

2021-11-03 Thread Rob Cliffe via Python-ideas
On 03/11/2021 18:28, Stephen J. Turnbull wrote: Chris Angelico writes: > While it's possible to avoid some of those, we can't hold the > language back because *someone who doesn't understand* might > misunderstand. Opposing the proposal wasn't the point of quoting Steve, the point was t

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

2021-11-03 Thread David Mertz, Ph.D.
On Wed, Nov 3, 2021, 9:19 PM Rob Cliffe via Python-ideas > Some people clearly need it, viz. those who use a default such as `[]` and > then ask on Stack Overflow why they get surprising results. This is silly. All those folks on StackOverflow are told "use a sentinel." The fact beginners can ma

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

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 12:42 PM David Mertz, Ph.D. wrote: > This seems exactly opposite the real situation. Late binding is completely > and straightforwardly handled by a sentinel. Yes, it doesn't make the > automatic help() that pretty. Yes it takes an extra line in the body. But the > semant

[Python-ideas] Re: Beginners accidentally shadow module names due to different expectation of the resolution order for module imports

2021-11-03 Thread Ricky Teachey
On Wed, Nov 3, 2021, 5:41 PM Chris Angelico wrote: On Thu, Nov 4, 2021 at 6:37 AM Ethan Furman wrote: > > On 11/3/21 12:21 PM, Florian Wetschoreck wrote: > > > In order to prevent confusion, I want to point out that the primary scenario that I meant is not that the file imports > > itself but

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults -- choice of -> vs @

2021-11-03 Thread Ricky Teachey
On Wed, Nov 3, 2021, 2:40 PM MRAB wrote: > On 2021-11-03 18:14, Ethan Furman wrote: > > On 11/3/21 10:35 AM, Steven D'Aprano wrote: > > > > > I suppose that we could even add yet another overloaded meaning on > the > > > asterix: > > > > > > # with no default, * keeps the old meaning

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

2021-11-03 Thread Christopher Barker
> For example, even though I was only lukewarm in support of the walrus > operator, I agree it makes a some code constructs more concise and more > readable. But it WAS new syntax to do the same thing that was already > possible with an extra line or two before. > > It's extra syntax to make a cer

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

2021-11-03 Thread Chris Angelico
On Thu, Nov 4, 2021 at 3:56 PM Christopher Barker wrote: > All that being said, like any other PEP, there are two questions: > > 1) will this be an improvement? > 2) if so, is it worth the churn? > > And the SC will need to make those decisions. > > FWIW, I’m not totally sure where I come down on