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

2022-06-18 Thread Lucas Wiman
I'm a little confused by the benchmark. Using re looks pretty competitive in terms of speed, and should be much more memory efficient. # https://www.gutenberg.org/cache/epub/100/pg100.txt (5.7mb; ~170K lines) with open('/tmp/shakespeare.txt', 'r') as f: text = f.read() import re from

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

2022-06-18 Thread Jonathan Slenders
Good catch! One correction here, I somewhat mixed up the benchmarks. I forgot both projects of mine required support for universal line endings exactly like splitlines() does this out of the box. That requires a more complex regex pattern. I was actually using: re.compile(r"\n|\r(?!\n)") And then

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

2022-06-18 Thread David Mertz, Ph.D.
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 opinion is different from yours is "adding FUD" and

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

2022-06-18 Thread Paul Moore
On Sat, 18 Jun 2022 at 03:45, Chris Angelico 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? > > > > # `defer n=len(items)` > > def

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

2022-06-18 Thread Rob Cliffe via Python-ideas
On 18/06/2022 03:28, Steven D'Aprano wrote: On Fri, Jun 17, 2022 at 06:32:36AM +0100, Rob Cliffe wrote: The bar for adding a new hard keyword to Python is very high. Likewise for new syntax. I would suggest less so, provided that it was previously illegal, because it's backward-compatible,

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

2022-06-18 Thread Christopher Barker
My first thought is that you are using the wrong data structure here— perhaps a list of lines would make more sense than one big ol’ string. That being said, a way to get all the indexes of a character could be useful I’d support that idea. -CHB On Fri, Jun 17, 2022 at 10:13 PM Jonathan

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

2022-06-18 Thread Stephen J. Turnbull
Chris Angelico writes: > And there we have it. People are complaining loudly, but then ALSO > saying that they don't support the proposal anyway. Why are you > bothering to debate this if you've already made your decision? I can't speak for Brendan, but I have two reasons for discussing

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

2022-06-18 Thread Paul Moore
On Sat, 18 Jun 2022 at 15:53, Stephen J. Turnbull wrote: > I don't find that burdensome enough to want syntax, and I can't guess > how quickly I'd start using it if available, that probably depends on > how often the community seems to be using it (ie, in the code I'm > reading). To be honest, I

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

2022-06-18 Thread David Mertz, Ph.D.
I think the example that Steven gave, and Stephen approximately repeats is good. def func(items=[], n=later len(items)): items.append("Hello") print(n) func() > I guess Chris will say 0 and David will say 1, but I might be wrong about either of them. This is correct.

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

2022-06-18 Thread Stephen J. Turnbull
Steven D'Aprano writes: > The match...case statement didn't "need" keywords either, we could have > picked symbols instead if we wanted to look like APL. Remember that > keywords have advantages as well as disadvantages. Given the existence > of community support for keywords, the PEP

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

2022-06-18 Thread Paul Moore
On Sat, 18 Jun 2022 at 21:57, Jonathan Slenders wrote: > > Good catch! One correction here, I somewhat mixed up the benchmarks. I forgot > both projects of mine required support for universal line endings exactly > like splitlines() does this out of the box. That requires a more complex >

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

2022-06-18 Thread Eric V. Smith via Python-ideas
On 6/18/2022 5:34 PM, Paul Moore wrote: After all, it has the advantage of working on older versions of Python (and given that one of your use cases is Textual, I can't imagine anyone would be happy if that required Python 2.12+...) Guido's "no 2.8" shirt apparently didn't stop 2.9 through

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

2022-06-18 Thread Paul Moore
On Sat, 18 Jun 2022 at 23:15, Eric V. Smith via Python-ideas wrote: > > On 6/18/2022 5:34 PM, Paul Moore wrote: > > After all, it has the > > advantage of working on older versions of Python (and given that one > > of your use cases is Textual, I can't imagine anyone would be happy if > > that

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

2022-06-18 Thread Jeremiah Gabriel Pascual
> This makes me realize that `str.indexes(char)` is actually not what I need, > but really a `str.line_offsets()` which returns exactly the positions that > `str.splitlines()` would use. Does that make sense? I'm also thinking of a generic `str.split_indices(char)` that handles all characters

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

2022-06-18 Thread MRAB
On 2022-06-18 21:55, Jonathan Slenders wrote: Good catch! One correction here, I somewhat mixed up the benchmarks. I forgot both projects of mine required support for universal line endings exactly like splitlines() does this out of the box. That requires a more complex regex pattern. I was

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

2022-06-18 Thread Rob Cliffe via Python-ideas
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: Element 42 of iterator has already been used (Apologies if I don't know the difference

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

2022-06-18 Thread Inada Naoki
On Sat, Jun 18, 2022 at 5:13 AM Jonathan Slenders wrote: > First time, it was needed in prompt_toolkit, where I spent a crazy amount of > time looking for the most performant solution. > Third time is for the Rich/Textual project from Will McGugan. (See: >

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

2022-06-18 Thread Rob Cliffe via Python-ideas
Sorry, but I think all this talk about lazy evaluation is a big red herring:     (1) Python is not Haskell or Dask.     (2) Lazy evaluation is something Python doesn't have, and would be a HUGE amount of work for Chris (or anyone) to implement (much more, I would think, than he has already put