Re: [Python-ideas] In fact, I'm a bit worry about this literal p""

2018-12-31 Thread Yuval Greenfield
On Fri, Dec 28, 2018 at 1:56 AM Ma Lin wrote: > Maybe this literal will encourage people to finish tasks using regex, > even lead to abuse regex, will this change Python's style? > > What's worse is, people using mixed manners in the same project: > > one_line.split(',') > ... > p','.split(one_li

Re: [Python-ideas] In fact, I'm a bit worry about this literal p""

2018-12-31 Thread Steven D'Aprano
On Mon, Dec 31, 2018 at 12:48:56AM -0800, Yuval Greenfield wrote: > In my opinion, only if this change would make 50% of programs run 50% > faster then it might be worth discussing. What if it were 100% of programs 25% faster? *wink* Generally speaking, we don't introduce new syntax as a speed

[Python-ideas] No need to add a regex pattern literal

2018-12-31 Thread Antoine Pitrou
On Thu, 27 Dec 2018 19:48:40 +0800 Ma Lin wrote: > We can use this literal to represent a compiled pattern, for example: > > >>> p"(?i)[a-z]".findall("a1B2c3") > ['a', 'B', 'c'] > > >>> compiled = p"(?<=abc)def" > >>> m = compiled.search('abcdef') > >>> m.group(0) > 'def' > > >>> rp'\W

Re: [Python-ideas] No need to add a regex pattern literal

2018-12-31 Thread Antoine Pitrou
Le 31/12/2018 à 12:31, M.-A. Lemburg a écrit : > > We already have re.search() and re.match() which deal with compilation > on-the-fly and caching. Perhaps the documentation should hint at this > more explicitly... The complaint is that the global cache is still too costly. See measurements in h

Re: [Python-ideas] No need to add a regex pattern literal

2018-12-31 Thread M.-A. Lemburg
On 31.12.2018 12:23, Antoine Pitrou wrote: > On Thu, 27 Dec 2018 19:48:40 +0800 > Ma Lin wrote: >> We can use this literal to represent a compiled pattern, for example: >> >> >>> p"(?i)[a-z]".findall("a1B2c3") >> ['a', 'B', 'c'] >> >> >>> compiled = p"(?<=abc)def" >> >>> m = compiled.search('

Re: [Python-ideas] In fact, I'm a bit worry about this literal p""

2018-12-31 Thread Anders Hovmöller
>regex = re.compile(r"...") >regex = p("...") > > is not that much different. True, but when the literal is put somewhere far from the compile() call it becomes a problem for static analysis. Conceptually a regex is not a string but an embedded foreign language. That's why I think thi

Re: [Python-ideas] No need to add a regex pattern literal

2018-12-31 Thread Ma Lin
On 18-12-31 19:47, Antoine Pitrou wrote: > The complaint is that the global cache is still too costly. > See measurements in https://bugs.python.org/issue35559 In this issue, using a global variable `_has_non_base16_digits` [1] will accelerate 30%. Is re module's internal cache [2] so bad? If