[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Serhiy Storchaka
06.12.19 04:31, Guido van Rossum пише: (There are apparently subtle differences between re.search() and re.findall() -- not sure if they matter in this case.) There is no any differences. Also, analyzing examples from GitHub, in most cases the pattern contains no or single group, so the code

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Serhiy Storchaka
05.12.19 23:47, Kyle Stanley пише: Serhiy Storchaka wrote: > We still do not know a use case for findfirst. If the OP would show his > code and several examples in others code this could be an argument for > usefulness of this feature. I'm not sure about the OP's exact use case, but using Gi

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Guido van Rossum
On Thu, Dec 5, 2019 at 22:08 Jonathan Goble wrote: > On Fri, Dec 6, 2019, 12:47 AM Steven D'Aprano wrote: > >> On Thu, Dec 05, 2019 at 05:40:05PM -0400, Juancarlo Añez wrote: >> > I just found this code: >> > >> > def get_product_item(jsonld_items): >> > for item in jsonld_items: >> >

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Jonathan Goble
On Fri, Dec 6, 2019, 12:47 AM Steven D'Aprano wrote: > On Thu, Dec 05, 2019 at 05:40:05PM -0400, Juancarlo Añez wrote: > > I just found this code: > > > > def get_product_item(jsonld_items): > > for item in jsonld_items: > > if item['@type'] == 'Product': > > return item >

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Steven D'Aprano
On Thu, Dec 05, 2019 at 05:40:05PM -0400, Juancarlo Añez wrote: > I just found this code: > > def get_product_item(jsonld_items): > for item in jsonld_items: > if item['@type'] == 'Product': > return item > else: > return {} I'm sorry, I can't tell what that is

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Guido van Rossum
On Thu, Dec 5, 2019 at 6:16 PM Juancarlo Añez wrote: > It’s unfortunate that these functions aren’t better matched. Why is there >> a simple-semantics find-everything and a match-semantics find-iteratively >> and find-one? But I don’t think adding a simple-semantics find-one that >> works by inef

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Juancarlo Añez
> > It’s unfortunate that these functions aren’t better matched. Why is there > a simple-semantics find-everything and a match-semantics find-iteratively > and find-one? But I don’t think adding a simple-semantics find-one that > works by inefficiently finding all is the right solution. > The prop

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Sebastian Kreft
To overcome Github's search limitations, one can use Chrome's codesearch or the public github dataset available on bigquery (note: it's only a sample from 2012 if I'm not mistaken). https://cs.chromium.org/search/?q=lang:py+re%5C.findall%5C(.*%5C)%5C%5B0%5C%5D&sq=package:chromium&type=cs returns 5

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Ethan Furman
On 12/05/2019 03:11 PM, Josh Rosenberg wrote: "Also, the for-loop version quits the moment it finds a Product type, while the `first` version has to first process the entire jsonld_items structure." The first version doesn't have to process the whole structure; it's written with a generator e

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Josh Rosenberg
"Also, the for-loop version quits the moment it finds a Product type, while the `first` version has to first process the entire jsonld_items structure." The first version doesn't have to process the whole structure; it's written with a generator expression, so it only tests and produces values on

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Guido van Rossum
I have encountered plenty of uses for first(), usually the argument is a list or even a dict or set that’s already computed — for sets, it’s common that it’s known there’s only one element, the question is how to get that element. On Thu, Dec 5, 2019 at 14:28 Andrew Barnert via Python-ideas < pyth

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Andrew Barnert via Python-ideas
On Dec 5, 2019, at 13:43, Juancarlo Añez wrote: > >  > I just found this code: > > def get_product_item(jsonld_items): > for item in jsonld_items: > if item['@type'] == 'Product': > return item > else: > return {} > > My argument is that the intent is cleare

[Python-ideas] Re: Argumenting in favor of first()

2019-12-05 Thread Ethan Furman
On 12/05/2019 01:40 PM, Juancarlo Añez wrote: I just found this code: def get_product_item(jsonld_items):     for item in jsonld_items:         if item['@type'] == 'Product':             return item     else:         return {} My argument is that the intent is cle

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Kyle Stanley
Serhiy Storchaka wrote: > We still do not know a use case for findfirst. If the OP would show his > code and several examples in others code this could be an argument for > usefulness of this feature. I'm not sure about the OP's exact use case, but using GitHub's code search for .py files that mat

[Python-ideas] Argumenting in favor of first()

2019-12-05 Thread Juancarlo Añez
I just found this code: def get_product_item(jsonld_items): for item in jsonld_items: if item['@type'] == 'Product': return item else: return {} My argument is that the intent is clearer in: def get_product_item(jsonld_items): return first((item for item

[Python-ideas] Re: lowercase exception names trip-up .

2019-12-05 Thread Matthias Bussonnier
Thanks for pointing those out. At least when the alias is `error = OtherName` the text is the stack trace are informative. -- M ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org ht

[Python-ideas] Re: lowercase exception names trip-up .

2019-12-05 Thread Serhiy Storchaka
05.12.19 21:25, Matthias Bussonnier пише: I've been tripped up a couple of time by a few Exception names being lower case both in code and tracebacks. In particular `error` (all lower case) I tend to read `error` as a function instead of a class. According to my non-scientific grep-foo, I find

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Serhiy Storchaka
05.12.19 21:07, Guido van Rossum пише: The case for findfirst() becomes stronger! There seem plenty of ways to get this wrong. I write several functions every day. There are many ways to get this wrong. But I do not propose to include all these functions in the stdlib. If I want to include ev

[Python-ideas] lowercase exception names trip-up .

2019-12-05 Thread Matthias Bussonnier
I've been tripped up a couple of time by a few Exception names being lower case both in code and tracebacks. In particular `error` (all lower case) I tend to read `error` as a function instead of a class. According to my non-scientific grep-foo, I find that ~ 300 descendant from Exceptions st

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Guido van Rossum
The case for findfirst() becomes stronger! There seem plenty of ways to get this wrong. On Thu, Dec 5, 2019 at 09:30 Andrew Barnert via Python-ideas < python-ideas@python.org> wrote: > On Dec 5, 2019, at 08:53, Juancarlo Añez wrote: > > > > The proposed implementation of a findfirst() would hand

[Python-ideas] Re: Allow user extensions to operators [related to: Moving PEP 584 forward (dict + and += operators)]

2019-12-05 Thread Brett Cannon
On Wed, Dec 4, 2019 at 3:12 PM Guido van Rossum wrote: > We could treat it as a kind of future statement. If there’s a top level > statement that defines the magic identitier we generate the special > bytecode. > True, that would help solve the performance issue. But I'm still -1 on the idea re

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Andrew Barnert via Python-ideas
On Dec 5, 2019, at 08:53, Juancarlo Añez wrote: > > > The proposed implementation of a findfirst() would handle many common cases, > and be friendly to newcomers (why do I need to deal with a Match object?), > specially if the semantics are those of findall(): > > next(iter(findall(...))

[Python-ideas] Re: Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Andrew Barnert via Python-ideas
On Dec 5, 2019, at 08:53, Juancarlo Añez wrote: > > BTW, a common function in extensions to itertools is first(): > > def first(seq, default=None): > return next(iter(seq), default= default) > > That function, first(), would also be a nice addition in itertools, and > findfirst() c

[Python-ideas] Fwd: Re: Fwd: re.findfirst()

2019-12-05 Thread Juancarlo Añez
On Wed, Dec 4, 2019 at 3:02 PM Guido van Rossum wrote: > Fair enough. I’ll let the OP defend his use case. > The OP thinks that the case for wanting just the string for a first regex match, or a verifiable default if there is no match, is way too common, that the advice on the web is not very go

[Python-ideas] Re: Suggestion for language addition

2019-12-05 Thread Eric Fahlgren
My little experiments in 3.7 show exception setup is about 40% more costly than just a do-nothing loop, but execution of is about 9x more expensive than doing nothing, so actually very little cost if your loop only rarely catches the exception (I assume you'll probably actually do something inside