[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 15:48, Brendan Barnwell wrote: > > On 2022-06-20 22:26, Chris Angelico wrote: > > Okay, here's a compromise. > > > > Go and write a full and detailed specification of the Python-visible > > semantics of deferred evaluation objects, including how they would be > > used to imp

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Brendan Barnwell
On 2022-06-20 22:26, Chris Angelico wrote: Okay, here's a compromise. Go and write a full and detailed specification of the Python-visible semantics of deferred evaluation objects, including how they would be used to implement late-bound argument defaults. Go and actually do some real work on y

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Piotr Duda
wt., 21 cze 2022 o 05:20 Steven D'Aprano napisał(a): > The point is, Rob thought (and possibly still does, for all I know) that > lazy evaluation is completely orthogonal to late-bound defaults. The PEP > makes that claim too, even though it is not correct. With a couple of > tweaks that we have

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 13:17, Steven D'Aprano wrote: > > On Tue, Jun 21, 2022 at 12:13:08AM +1000, Chris Angelico wrote: > > > Nice analogy. It doesn't hold up. > > > > Consider this function: > > > > def f(stuff, max=>len(stuff)): > > stuff.append(1) > > print(max) > > > > f([1,2,3]) > >

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 13:07, Steven D'Aprano wrote: > > On Tue, Jun 21, 2022 at 03:15:32AM +0100, Rob Cliffe wrote: > > > Why do people keep obscuring the discussion of a PEP which addresses > > Problem A by throwing in discussion of the (unrelated) Problem B? > > (Chris, and I, have stated, ad n

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread David Mertz, Ph.D.
It seems like this is all an occasion to use itertools.tee() ... But with a consciousness that implicit caching uses memory. On Mon, Jun 20, 2022, 11:36 PM Steven D'Aprano wrote: > On Sun, Jun 19, 2022 at 01:34:35AM +0100, Rob Cliffe via Python-ideas > wrote: > > > To me, the natural implementat

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread Steven D'Aprano
On Sun, Jun 19, 2022 at 01:34:35AM +0100, Rob Cliffe via Python-ideas wrote: > To me, the natural implementation of slicing on a non-reusable iterator > (such as a generator) would be that you are not allowed to go backwards > or even stand still: >     mygen[42] >     mygen[42] > ValueError: El

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Steven D'Aprano
On Tue, Jun 21, 2022 at 12:13:08AM +1000, Chris Angelico wrote: > Nice analogy. It doesn't hold up. > > Consider this function: > > def f(stuff, max=>len(stuff)): > stuff.append(1) > print(max) > > f([1,2,3]) > > How would you use lazy evaluation to *guarantee* the behaviour here? By

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Steven D'Aprano
On Tue, Jun 21, 2022 at 03:15:32AM +0100, Rob Cliffe wrote: > Why do people keep obscuring the discussion of a PEP which addresses > Problem A by throwing in discussion of the (unrelated) Problem B? > (Chris, and I, have stated, ad nauseam, that these *are* unrelated > problems. Chris says: "E

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Rob Cliffe via Python-ideas
On 18/06/2022 15:51, Stephen J. Turnbull wrote: > This raises another choice: should lazy defaults be evaluated before > entering the body of the function, or at the point where the parameter > is used? Which would be more useful? Both are potentially useful. Yes, both *ARE* potentially

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 11:07, Rob Cliffe via Python-ideas wrote: > > > > On 20/06/2022 17:39, Jeremiah Paige wrote: > > On Sat, Jun 18, 2022 at 5:42 PM Rob Cliffe via Python-ideas > wrote: >> >> To me, the natural implementation of slicing on a non-reusable iterator >> (such as a generator) woul

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread Rob Cliffe via Python-ideas
On 20/06/2022 17:39, Jeremiah Paige wrote: On Sat, Jun 18, 2022 at 5:42 PM Rob Cliffe via Python-ideas wrote: To me, the natural implementation of slicing on a non-reusable iterator (such as a generator) would be that you are not allowed to go backwards or even stand stil

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 10:13, Rob Cliffe via Python-ideas wrote: > > On 19/06/2022 04:42, David Mertz, Ph.D. wrote: > > On Sat, Jun 18, 2022, 9:21 PM Rob Cliffe >> >> Sorry again, but IMO discussing any model except one where late-bound >> defaults are evaluated at function call time is just addi

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Rob Cliffe via Python-ideas
On 19/06/2022 04:42, David Mertz, Ph.D. wrote: On Sat, Jun 18, 2022, 9:21 PM Rob Cliffe Sorry again, but IMO discussing any model except one where late-bound defaults are evaluated at function call time is just adding FUD. It's definitely rude to repeatedly state that anyone who's

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Rob Cliffe via Python-ideas
On 19/06/2022 04:42, David Mertz, Ph.D. wrote: On Sat, Jun 18, 2022, 9:21 PM Rob Cliffe Sorry again, but IMO discussing any model except one where late-bound defaults are evaluated at function call time is just adding FUD. It's definitely rude to repeatedly state that anyone who's

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Mike Miller
On 2022-06-20 03:34, Paul Moore wrote: For the record, I think the islice solution is sufficient for this case. But I have needed this sort of thing occasionally, and islice The post above sums it up for me. We have next() for one to a few, islice for several to zillions, and a for-enumera

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Paul Moore
On Mon, 20 Jun 2022 at 18:42, Steve Jorgensen wrote: > > Steven D'Aprano wrote: > > Okay, I'm convinced. > > If we need this feature (and I'm not convinced about that part), then it > > makes sense to keep the star and write it as `spam, eggs, *... = items`. > > I thought about that, but to me, th

[Python-ideas] Re: Add a line_offsets() method to str

2022-06-20 Thread Steve Jorgensen
Steve Jorgensen wrote: > Jonathan Slenders wrote: > > Hi everyone, > > Today was the 3rd time I came across a situation where it was needed to > > retrieve all the positions of the line endings (or beginnings) in a very > > long python string as efficiently as possible. First time, it was needed in

[Python-ideas] Re: Add a line_offsets() method to str

2022-06-20 Thread Steve Jorgensen
Jonathan Slenders wrote: > Hi everyone, > Today was the 3rd time I came across a situation where it was needed to > retrieve all the positions of the line endings (or beginnings) in a very > long python string as efficiently as possible. First time, it was needed in > prompt_toolkit, where I spent

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Steve Jorgensen
Steven D'Aprano wrote: > Okay, I'm convinced. > If we need this feature (and I'm not convinced about that part), then it > makes sense to keep the star and write it as `spam, eggs, *... = items`. I thought about that, but to me, there are several reasons to not do that and to have the ellipsis m

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 01:44, MRAB wrote: > > On 2022-06-20 15:05, Chris Angelico wrote: > > On Mon, 20 Jun 2022 at 21:11, Jonathan Fine wrote: > >> > >> Hi > >> > >> Some have liked adding a new syntax > >> a, b, ... = iterable > >> to mean consume two items from the iterable. However, > >>

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread Jeremiah Paige
On Sat, Jun 18, 2022 at 5:42 PM Rob Cliffe via Python-ideas < python-ideas@python.org> wrote: > To me, the natural implementation of slicing on a non-reusable iterator > (such as a generator) would be that you are not allowed to go backwards > or even stand still: > mygen[42] > mygen[42]

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread Mathew Elman
Chris Angelico wrote: > On Mon, 20 Jun 2022 at 21:11, Mathew Elman mathew.el...@ocado.com wrote: > > This I like - it seems very intuitive, almost like an irreversible io > > stream. > > I don't know if there would be cases where this would lead to unexpected > > bugs, but without looking into it

[Python-ideas] Re: Add a line_offsets() method to str

2022-06-20 Thread MRAB
On 2022-06-20 16:12, Christopher Barker wrote: Hmm - I’m a bit confused about how you handle mixed / multiple line endings. If you use splitlines(), then it will remove the line endings, so if there are two-char line endings, then you’ll get off by one errors, yes? I would think you could loo

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread MRAB
On 2022-06-20 15:05, Chris Angelico wrote: On Mon, 20 Jun 2022 at 21:11, Jonathan Fine wrote: Hi Some have liked adding a new syntax a, b, ... = iterable to mean consume two items from the iterable. However, a, b, Ellipsis = iterable has a different meaning (at least in Python 3.8). It

[Python-ideas] Re: Add a line_offsets() method to str

2022-06-20 Thread Christopher Barker
Hmm - I’m a bit confused about how you handle mixed / multiple line endings. If you use splitlines(), then it will remove the line endings, so if there are two-char line endings, then you’ll get off by one errors, yes? I would think you could look for “\n”, and get the correct answer ( with extran

[Python-ideas] Re: Add a line_offsets() method to str

2022-06-20 Thread Christopher Barker
If you are working with bytes, then numpy could be perfect— not a small dependency of course, but it should work, and work fast. And a cython method would be quite easy to write, but of course substantially harder to distribute :-( -CHB On Sun, Jun 19, 2022 at 5:30 PM Jonathan Slenders wrote:

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Jonathan Fine
Hi Some of us might believe that a currently legal syntax should only exceptionally be given a new meaning, even if there is no evidence whatsoever that this legal syntax is actually in use. My own belief is more pragmatic. If there's very strong evidence that the syntax is not in use, I'm happy t

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Chris Angelico
On Mon, 20 Jun 2022 at 21:19, Steven D'Aprano wrote: > > (4) The guarantee that a late-bound default WILL be executed at > > function call time, can be useful, even essential (it could be > > time-dependent or it could depend on the values - default or otherwise - > > of other parameters whose

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Chris Angelico
On Mon, 20 Jun 2022 at 21:11, Jonathan Fine wrote: > > Hi > > Some have liked adding a new syntax > a, b, ... = iterable > to mean consume two items from the iterable. However, >a, b, Ellipsis = iterable > has a different meaning (at least in Python 3.8). It redefines Ellipsis. (As > an e

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread Chris Angelico
On Mon, 20 Jun 2022 at 21:11, Mathew Elman wrote: > > This I like - it seems very intuitive, almost like an irreversible io stream. > > I don't know if there would be cases where this would lead to unexpected > bugs, but without looking into it it seems nice. > > Question: What would be the natur

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Steven D'Aprano
On Sun, Jun 19, 2022 at 02:21:16AM +0100, Rob Cliffe via Python-ideas wrote: > Sorry, but I think all this talk about lazy evaluation is a big red herring: >     (1) Python is not Haskell or Dask. Python is not Haskell, but we stole list comprehensions and pattern matching from it. Python steals

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Jonathan Fine
Hi Some have liked adding a new syntax a, b, ... = iterable to mean consume two items from the iterable. However, a, b, Ellipsis = iterable has a different meaning (at least in Python 3.8). It redefines Ellipsis. (As an explicit constant, '...' can be redefined.) The syntax a, b, ... = i

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread Mathew Elman
This I like - it seems very intuitive, almost like an irreversible io stream. I don't know if there would be cases where this would lead to unexpected bugs, but without looking into it it seems nice. Question: What would be the natural behaviour for negative indices? Raising an error?

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Paul Moore
On Mon, 20 Jun 2022 at 11:08, Steven D'Aprano wrote: > But that's basically islice. So: > > # Its okay to put reusable helper functions in a module. > # Not everything has to be syntax. > first, second, third = itertools.islice(items, 3) > > I think that we have a working solution for

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Steven D'Aprano
On Sun, Jun 19, 2022 at 11:03:45PM -0700, Jeremiah Paige wrote: > What if next grew a new argument? Changing the signature of a builtin is a > big change, but surely not bigger than new syntax? If we could ask for the > number of items returned the original example might look like > > >>> first,

[Python-ideas] Re: Bare wildcard in de-structuring to ignore remainder and stop iterating (restart)

2022-06-20 Thread Lucas Wiman
Some background. PEP 3132 (https://peps.python.org/pep-3132/) lists the following: > > Possible changes discussed were: > > >- Only allow a starred expression as the last item in the exprlist. >This would simplify the unpacking code a bit and allow for the starred >expression to be assi

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Stephen J. Turnbull
@Chris My bottom line, as I wrote before, is that even if this were introduced, I probably will continue to default to def foo(arg=None): if arg is None: arg = default in my own code until I start seeing "def foo(arg=>default)" in a lot of code I read. Since Mailman gene