On 23 November 2017 at 13:11, Paul Moore <p.f.mo...@gmail.com> wrote:
> On 23 November 2017 at 12:01, Ivan Levkivskyi <levkivs...@gmail.com> > 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 us trying to keep up with the discussion who don't have > time to chase the various references, and in the interest of keeping > the discussion in one place, can you summarise the real-world use > cases from the SO questions here? (I assume they are real world cases, > and not just theoretical questions) > OK, here are the links: https://stackoverflow.com/questions/45190729/differences-between-generator-comprehension-expressions https://stackoverflow.com/questions/29334054/why-am-i-getting-different-results-when-using-a-list-comprehension-with-coroutin https://bugs.python.org/issue10544 https://bugs.python.org/issue3267 In all four cases pattern is the same, people were trying to refactor something like this: def f(): res = [] for x in y: r = yield x res.append(r) return res into something like this: def f(): return [(yield x) for x in y] My understanding is that none of the case is _pressing_, since they all start with a for-loop, but following this logic comprehensions themselves are not needed. Nevertheless people use them because they like it. The problem in all four cases is that they got hard to debug problem, since calling `f()` returns a generator, just not the one they would expect. -- Ivan
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com