Re: [Python-Dev] Python initialization and embedded Python

2017-11-23 Thread Serhiy Storchaka
24.11.17 04:21, Glenn Linderman пише: On 11/23/2017 5:31 PM, Nick Coghlan wrote: - a consolidated list of *all* the APIs that can safely be called before Py_Initialize So it is interesting to know that list, of course, but the ones that are to be supported and documented might be a smaller list

Re: [Python-Dev] Python initialization and embedded Python

2017-11-23 Thread Nick Coghlan
On 24 November 2017 at 12:21, Glenn Linderman wrote: > On 11/23/2017 5:31 PM, Nick Coghlan wrote: > > - a consolidated list of *all* the APIs that can safely be called before > Py_Initialize > > So it is interesting to know that list, of course, but the ones that are > to be supported and documen

Re: [Python-Dev] Python initialization and embedded Python

2017-11-23 Thread Glenn Linderman
On 11/23/2017 5:31 PM, Nick Coghlan wrote: - a consolidated list of *all* the APIs that can safely be called before Py_Initialize So it is interesting to know that list, of course, but the ones that are to be supported and documented might be a smaller list. Or might not. ___

Re: [Python-Dev] Python initialization and embedded Python

2017-11-23 Thread Nick Coghlan
On 24 November 2017 at 09:19, Victor Stinner wrote: > Hi, > > We are close to the 3.7a3 release and the bug is not fixed yet. I > propose to revert the changes on memory allocators right now, and take > time to design a proper fix which will respect all constraints. > > https://github.com/python/

Re: [Python-Dev] PEP 559 - built-in noop()

2017-11-23 Thread Nick Coghlan
On 24 November 2017 at 01:49, Barry Warsaw wrote: > On Nov 22, 2017, at 19:32, Victor Stinner > wrote: > > > > Aha, contextlib.nullcontext() was just added, cool! > > So, if I rewrite PEP 559 in terms of decorators it won’t get rejected? > The conceptual delta between knowing how to call "noop(

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Nick Coghlan
On 23 November 2017 at 23:04, Ivan Levkivskyi wrote: > I don't see why this particular case qualifies for such a radical measure > as an exception to syntactic rules, > instead of just fixing it (sorry Nick :-) > I've posted in more detail about this to the issue tracker, but the argument here i

Re: [Python-Dev] Python initialization and embedded Python

2017-11-23 Thread Victor Stinner
Hi, We are close to the 3.7a3 release and the bug is not fixed yet. I propose to revert the changes on memory allocators right now, and take time to design a proper fix which will respect all constraints. https://github.com/python/cpython/pull/4532 Today, someone came to me on IRC to complain th

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Guido van Rossum wrote: the extra scope is now part of the language definition. It can't be removed as a "bug fix". Does anyone actually rely on the scope-ness of comprehensions in any way other than the fact that it prevents local variable leakage? If not, probably nobody would notice if it w

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Guido van Rossum wrote: The debugger does stop at each iteration. It does see a local named ".0" I suppose there currently is no way for the debugger to map the variable names to what they are named in the source, right? If the hidden local were named "a.0" where "a" is the original name, ma

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Serhiy Storchaka wrote: Ivan explained that this function should be rough equivalent to def f(): t = [(yield i) for i in range(3)] return (x for x in t) This seems useless to me. It turns a lazy iterator into an eager one, which is a gross violation of the author's intent in

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Paul Moore wrote: has anyone confirmed why a function scope was considered necessary at the time of the original implementation, but it's apparently not now? At the time I got the impression that nobody wanted to spend the time necessary to design and implement a subscope mechanism. What's chan

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Guido van Rossum
On Thu, Nov 23, 2017 at 9:06 AM, Serhiy Storchaka wrote: > 23.11.17 18:08, Guido van Rossum пише: > >> This thread is still going over the speed limit. Don't commit anything >> without my explicit approval. >> > > I'm not going to write a single line of code while the decision about this > issue

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Serhiy Storchaka
23.11.17 18:08, Guido van Rossum пише: This thread is still going over the speed limit. Don't commit anything without my explicit approval. I'm not going to write a single line of code while the decision about this issue is not made. This is not easy issue. A problem with dropping the "funct

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Brett Cannon
I've now ended up in Guido's boat of needing a summary since I think this thread has grown to cover whether yield should be allowed in comprehensions, something about await in comprehensions, and now about leaking the loop variable (or some implementation detail). IOW there seems to be 3 separate d

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Guido van Rossum
This thread is still going over the speed limit. Don't commit anything without my explicit approval. I know one thing for sure. The choice to make all comprehensions functions was quite intentional (even though alternatives were also discussed) and the extra scope is now part of the language defin

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ethan Furman
On 11/23/2017 04:01 AM, Ivan Levkivskyi wrote: Lets just forget about two SO questions and dozens people who up-voted it. Questions/answers are routinely up-voted because they are well-written and/or informative, not just because somebody had a need for it or a use for the answer. The SO qu

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 15:37, Ethan Furman wrote: > On 11/22/2017 11:51 PM, Sven R. Kunze wrote: > >> A "yield" within a comprehension is like a "return" in a comprehension. It >> makes no sense at all. >> Also a "yield" and a "return with value" is also rarely seen. >> >> Comprehensions build new

Re: [Python-Dev] PEP 559 - built-in noop()

2017-11-23 Thread Barry Warsaw
On Nov 22, 2017, at 19:32, Victor Stinner wrote: > > Aha, contextlib.nullcontext() was just added, cool! So, if I rewrite PEP 559 in terms of decorators it won’t get rejected? from functools import wraps def noop(func): @wraps(func) def wrapper(*args, **kws): return None re

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ethan Furman
On 11/22/2017 11:51 PM, Sven R. Kunze wrote: A "yield" within a comprehension is like a "return" in a comprehension. It makes no sense at all. Also a "yield" and a "return with value" is also rarely seen. Comprehensions build new objects, they are not for control flow, IMO. +1 -- ~Ethan~ __

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 15:30, Paul Moore wrote: > On 23 November 2017 at 14:24, Ivan Levkivskyi > wrote: > >> My main concern is that comprehension is not equivalent to a for loop > >> for a specific reason - the scope issue. Has anyone looked back at the > >> original discussions to confirm *wh

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Serhiy Storchaka
23.11.17 16:30, Paul Moore пише: Ok, cool. My main point still applies though - has anyone confirmed why a function scope was considered necessary at the time of the original implementation, but it's apparently not now? I'm pretty sure it was a deliberate choice, not an accident. The implementa

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 14:24, Ivan Levkivskyi wrote: >> My main concern is that comprehension is not equivalent to a for loop >> for a specific reason - the scope issue. Has anyone looked back at the >> original discussions to confirm *why* a function was used? >> >> My recollection: >> >> >>> i =

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Chris Angelico
On Fri, Nov 24, 2017 at 1:21 AM, Paul Moore wrote: > On 23 November 2017 at 13:04, Ivan Levkivskyi wrote: >> Let us forget for a moment about other problems and focus on this one: list >> comprehension is currently not equivalent to a for-loop. >> There are two options: >> - Fix this, i.e. make c

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 15:21, Paul Moore wrote: > On 23 November 2017 at 13:04, Ivan Levkivskyi > wrote: > > Let us forget for a moment about other problems and focus on this one: > list > > comprehension is currently not equivalent to a for-loop. > > There are two options: > > - Fix this, i.e.

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 13:04, Ivan Levkivskyi wrote: > Let us forget for a moment about other problems and focus on this one: list > comprehension is currently not equivalent to a for-loop. > There are two options: > - Fix this, i.e. make comprehension equivalent to a for-loop even in edge > cases

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 14:54:27 +0200 Serhiy Storchaka wrote: > 23.11.17 14:30, Antoine Pitrou пише: > > On Thu, 23 Nov 2017 14:17:32 +0200 > > Serhiy Storchaka wrote: > >> > >> I used the "yield" statement, but I never used the "yield" expressions. > >> And I can't found examples. Could you plea

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 13:45, Paul Moore wrote: > On 23 November 2017 at 12:28, Ivan Levkivskyi > wrote: > > On 23 November 2017 at 13:11, Paul Moore wrote: > >> > >> On 23 November 2017 at 12:01, Ivan Levkivskyi > >> wrote: > >> > >> > "I don't use it, therefore it is not needed" is a great

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Serhiy Storchaka
23.11.17 14:30, Antoine Pitrou пише: On Thu, 23 Nov 2017 14:17:32 +0200 Serhiy Storchaka wrote: I used the "yield" statement, but I never used the "yield" expressions. And I can't found examples. Could you please present a real-world use case for the "yield" (not "yield from") expression? Of

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 12:42, Ivan Levkivskyi wrote: >> See e.g. http://www.tornadoweb.org/en/stable/gen.html >> > > Great, so I open this page and see this code: > > results = [] > for future in list_of_futures: > results.append(yield future) > > Interesting, why don't they use a comprehensio

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
Le 23/11/2017 à 13:42, Ivan Levkivskyi a écrit : > > Great, so I open this page and see this code: > > results = [] > for future in list_of_futures: >     results.append(yield future) > > Interesting, why don't they use a comprehension for this and instead > need to invent a whole `tornado.gen.

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 12:28, Ivan Levkivskyi wrote: > On 23 November 2017 at 13:11, Paul Moore wrote: >> >> On 23 November 2017 at 12:01, Ivan Levkivskyi >> wrote: >> >> > "I don't use it, therefore it is not needed" is a great argument, >> > thanks. >> > Lets just forget about two SO question

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 13:30, Antoine Pitrou wrote: > On Thu, 23 Nov 2017 14:17:32 +0200 > Serhiy Storchaka wrote: > > > > I used the "yield" statement, but I never used the "yield" expressions. > > And I can't found examples. Could you please present a real-world use > > case for the "yield" (n

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 12:01, Ivan Levkivskyi wrote: > "I don't use it, therefore it is not needed" is a great argument, thanks. > Lets just forget about two SO questions and dozens people who up-voted it. > Do you use async comprehensions? If not, then we don't need them either. For those of u

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 14:17:32 +0200 Serhiy Storchaka wrote: > > I used the "yield" statement, but I never used the "yield" expressions. > And I can't found examples. Could you please present a real-world use > case for the "yield" (not "yield from") expression? Of course I can. "yield" express

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 13:11, Paul Moore wrote: > On 23 November 2017 at 12:01, Ivan Levkivskyi > wrote: > > > "I don't use it, therefore it is not needed" is a great argument, > thanks. > > Lets just forget about two SO questions and dozens people who up-voted > it. > > Do you use async compre

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Serhiy Storchaka
23.11.17 13:49, Antoine Pitrou пише: I'm still in favour of deprecating and then disallowing. We could disallow it without deprecation. The current behavior definitely is wrong, nobody should depend on it. It should be either fixed or disallowed. Nobody seems to have presented a real-world

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
Le 23/11/2017 à 13:01, Ivan Levkivskyi a écrit : > > "I don't use it, therefore it is not needed"  is a great argument, thanks. This is just a data point. Some people seem to think that the construct is useful for asynchronous programming. In my experience it isn't. YMMV, etc. > Lets just for

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 12:49, Antoine Pitrou wrote: > On Thu, 23 Nov 2017 12:39:46 +0100 > Ivan Levkivskyi wrote: > > > > Also I think it makes sense to keep discussion in one place, i.e. either > > here xor at https://bugs.python.org/issue10544 > > The bug tracker can be used for implementation

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 09:50:27 + Paul Moore wrote: > On 23 November 2017 at 09:14, Steve Holden wrote: > > I would urge developers, in their improvements to the language to support > > asynchronous programming, to bear in mind that this is (currently) a > > minority use case. Why the rush to se

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 12:39:46 +0100 Ivan Levkivskyi wrote: > > Also I think it makes sense to keep discussion in one place, i.e. either > here xor at https://bugs.python.org/issue10544 The bug tracker can be used for implementation discussions, but general language design decisions (such as wheth

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 10:50, Paul Moore wrote: > On 23 November 2017 at 09:14, Steve Holden wrote: > > I would urge developers, in their improvements to the language to support > > asynchronous programming, to bear in mind that this is (currently) a > > minority use case. Why the rush to set co

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 12:38, Ivan Levkivskyi wrote: > On 23 November 2017 at 11:55, Nick Coghlan wrote: > >> On 23 November 2017 at 18:11, Greg Ewing >> wrote: >> >>> Ivan Levkivskyi wrote: >>> "People sometimes want to refactor for-loops containing `yield` into a comprehension but t

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 11:55, Nick Coghlan wrote: > On 23 November 2017 at 18:11, Greg Ewing > wrote: > >> Ivan Levkivskyi wrote: >> >>> "People sometimes want to refactor for-loops containing `yield` into a >>> comprehension but that doesn't work (particularly because of the hidden >>> function

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Nick Coghlan
On 23 November 2017 at 18:11, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> "People sometimes want to refactor for-loops containing `yield` into a >> comprehension but that doesn't work (particularly because of the hidden >> function scope) - lets make it a SyntaxError" >> > > Personally I'd be

Re: [Python-Dev] PEP 559 - built-in noop()

2017-11-23 Thread Nick Coghlan
On 23 November 2017 at 19:42, Chris Jerdonek wrote: > On Wed, Nov 22, 2017 at 4:32 PM, Victor Stinner > wrote: > >> Aha, contextlib.nullcontext() was just added, cool! >> > > So is this equivalent to-- > > @contextmanager > def yielding(x): > yield x > > I thought we were against

Re: [Python-Dev] Python initialization and embedded Python

2017-11-23 Thread Antoine Pitrou
On Thu, 23 Nov 2017 10:37:59 +0100 "M.-A. Lemburg" wrote: > On 18.11.2017 01:01, Victor Stinner wrote: > > Hi, > > > > The CPython internals evolved during Python 3.7 cycle. I would like to > > know if we broke the C API or not. > > > > Nick Coghlan and Eric Snow are working on cleaning up the P

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Paul Moore
On 23 November 2017 at 09:14, Steve Holden wrote: > I would urge developers, in their improvements to the language to support > asynchronous programming, to bear in mind that this is (currently) a > minority use case. Why the rush to set complex semantics in stone? +1 Also, given that languages

Re: [Python-Dev] PEP 559 - built-in noop()

2017-11-23 Thread Chris Jerdonek
On Wed, Nov 22, 2017 at 4:32 PM, Victor Stinner wrote: > Aha, contextlib.nullcontext() was just added, cool! > So is this equivalent to-- @contextmanager def yielding(x): yield x I thought we were against adding one-line functions? --Chris > > https://github.com/python/cpyt

Re: [Python-Dev] Python initialization and embedded Python

2017-11-23 Thread M.-A. Lemburg
On 18.11.2017 01:01, Victor Stinner wrote: > Hi, > > The CPython internals evolved during Python 3.7 cycle. I would like to > know if we broke the C API or not. > > Nick Coghlan and Eric Snow are working on cleaning up the Python > initialization with the "on going" PEP 432: > https://www.python.

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Steve Holden
On Wed, Nov 22, 2017 at 8:48 PM, Sven R. Kunze wrote: > Isn't yield like a return? > ​Enough like it to make a good case, I'd say.​ > A return in a list/dict/set comprehension makes no sense to me. > ​Nor me, nor the vast majority of instance. But nowadays yield is more of a synchronisation poi

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 09:17, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> "People sometimes want to refactor for-loops containing `yield` into a >> comprehension >> > > By the way, do we have any real-life examples of people wanting to > do this? It might help us decide what the semantics sho

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 09:11, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> "People sometimes want to refactor for-loops containing `yield` into a >> comprehension but that doesn't work (particularly because of the hidden >> function scope) - lets make it a SyntaxError" >> > > Personally I'd be

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Ivan Levkivskyi
On 23 November 2017 at 09:15, Greg Ewing wrote: > Ivan Levkivskyi wrote: > >> On 23 November 2017 at 05:44, Greg Ewing > > wrote: >> >>def g(): >> return ((yield i) for i in range(10)) >> >> >> I think this code should be just equivalent to th

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Ivan Levkivskyi wrote: "People sometimes want to refactor for-loops containing `yield` into a comprehension By the way, do we have any real-life examples of people wanting to do this? It might help us decide what the semantics should be. -- Greg ___

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Ivan Levkivskyi wrote: On 23 November 2017 at 05:44, Greg Ewing > wrote: def g(): return ((yield i) for i in range(10)) I think this code should be just equivalent to this code def g(): temp = [(yield i) for i in range(10)]

Re: [Python-Dev] Tricky way of of creating a generator via a comprehension expression

2017-11-23 Thread Greg Ewing
Ivan Levkivskyi wrote: "People sometimes want to refactor for-loops containing `yield` into a comprehension but that doesn't work (particularly because of the hidden function scope) - lets make it a SyntaxError" Personally I'd be fine with removing the implicit function scope from comprehensio