<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
24.11.2016, 23:23, Nathaniel Smith kirjoitti:<br>
<blockquote
cite="mid:CAPJVwBkKAjHU7LMG5=nUOMpQfsh=t3ODNHXCPC5S74JPBPu3Gg@mail.gmail.com"
type="cite">
<p dir="ltr">On Nov 23, 2016 11:29 PM, "Alex Grönholm" <<a
moz-do-not-send="true" href="mailto:alex.gronholm@nextday.fi">alex.gronholm@nextday.fi</a>>
wrote:<br>
><br>
> 23.11.2016, 01:34, Nathaniel Smith kirjoitti:<br>
>><br>
>> On Tue, Nov 22, 2016 at 2:22 PM, Alex Grönholm <<a
moz-do-not-send="true" href="mailto:alex.gronholm@nextday.fi">alex.gronholm@nextday.fi</a>>
wrote:<br>
>> > I'm not sure where asyncio_extras's async
generator implementation assumes<br>
>> > you're using asyncio. Could you elaborate on that?<br>
>><br>
>> If I'm reading it right, it assumes that the only two
things that might be yielded to the coroutine runner are either
(a) the special yield wrapper, or (b) an awaitable object like
an asyncio.Future. This works on asyncio, because that's all the
asyncio runner supports, but it doesn't work with (for example)
curio. async_generator (like native async generators) allows
arbitrary objects to be yielded to the coroutine runner.<br>
><br>
> You are misreading the code. It is in no way limited to
what asyncio accepts. It doesn't even import asyncio in the
asyncyield or generator modules. The only parts of the library
that depend on PEP 3156 event loops are the ones that involve
executors and threads.</p>
<p dir="ltr">I didn't say that it imported asyncio. I said that it
assumes the only things that will be yielded are the things that
asyncio yields. This is the line that I'm worried about:</p>
<p dir="ltr"> <a moz-do-not-send="true"
href="https://github.com/agronholm/asyncio_extras/blob/aec412e1b7034ca3cad386c381e655ce3547fee3/asyncio_extras/asyncyield.py#L40">https://github.com/agronholm/asyncio_extras/blob/aec412e1b7034ca3cad386c381e655ce3547fee3/asyncio_extras/asyncyield.py#L40</a></p>
<p dir="ltr">The code awaits the value yielded by the coroutine,
but there's no guarantee that this value is awaitable. It's an
arbitrary Python object representing a message sent to the
coroutine runner. It turns out that asyncio only uses awaitable
objects for its messages, so this code can get away with this on
asyncio, but if you try using this code with curio then I'm
pretty sure you're going to end up doing something like "await
(3,)" and then blowing up.</p>
</blockquote>
PEP 492 clearly states the following:<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<span style="color: rgb(68, 68, 68); font-family:
SourceSansProRegular, Arial, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: normal; letter-spacing:
normal; orphans: 2; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(249, 249, 249); display: inline !important;
float: none;"><br>
</span>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<span style="color: rgb(68, 68, 68); font-family:
SourceSansProRegular, Arial, sans-serif; font-size: 15px;
font-style: normal; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: normal; letter-spacing:
normal; orphans: 2; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(249, 249, 249); display: inline !important;
float: none;">It is a<span class="Apple-converted-space"> </span></span><tt
class="docutils literal" style="box-sizing: border-box; color:
rgb(68, 68, 68); font-style: normal; font-variant-ligatures:
normal; font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; orphans: 2; text-align: start;
text-indent: 0px; text-transform: none; white-space: normal;
widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(249, 249, 249);">TypeError<span
class="Apple-converted-space"> </span></tt><span style="color:
rgb(68, 68, 68); font-family: SourceSansProRegular, Arial,
sans-serif; font-size: 15px; font-style: normal;
font-variant-ligatures: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(249, 249,
249); display: inline !important; float: none;">to pass anything
other than an<span class="Apple-converted-space"> </span></span><em
style="box-sizing: border-box; margin: 0px; padding: 0px; border:
0px; font-style: italic; font-variant-ligatures: normal;
font-variant-caps: normal; font-variant-numeric: inherit;
font-weight: normal; font-stretch: inherit; font-size: 15px;
line-height: inherit; font-family: SourceSansProItalic, Arial,
sans-serif; vertical-align: baseline; color: rgb(68, 68, 68);
letter-spacing: normal; orphans: 2; text-align: start;
text-indent: 0px; text-transform: none; white-space: normal;
widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(249, 249, 249);">awaitable<span
class="Apple-converted-space"> </span></em><span style="color:
rgb(68, 68, 68); font-family: SourceSansProRegular, Arial,
sans-serif; font-size: 15px; font-style: normal;
font-variant-ligatures: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(249, 249,
249); display: inline !important; float: none;">object to an<span
class="Apple-converted-space"> </span></span><tt class="docutils
literal" style="box-sizing: border-box; color: rgb(68, 68, 68);
font-style: normal; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: normal; letter-spacing:
normal; orphans: 2; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
background-color: rgb(249, 249, 249);">await<span
class="Apple-converted-space"> </span></tt><span style="color:
rgb(68, 68, 68); font-family: SourceSansProRegular, Arial,
sans-serif; font-size: 15px; font-style: normal;
font-variant-ligatures: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(249, 249,
249); display: inline !important; float: none;">expression.</span><span
style="color: rgb(68, 68, 68); font-family: SourceSansProRegular,
Arial, sans-serif; font-size: 15px; font-style: normal;
font-variant-ligatures: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(249, 249,
249); display: inline !important; float: none;"><br>
</span>
<p>That (3,) is not an awaitable, so the example is invalid. That
said, I will re-examine this part of the implementation and
correct it if necessary. So far I just haven't encountered
anything that would produce an error.<br>
</p>
<blockquote
cite="mid:CAPJVwBkKAjHU7LMG5=nUOMpQfsh=t3ODNHXCPC5S74JPBPu3Gg@mail.gmail.com"
type="cite">
<p dir="ltr">>> > Native async generators don't support
"yield from" either, so I didn't try<br>
>> > to add that until there's a new PEP that defines
its exact semantics.<br>
>><br>
>> Yeah, one of the motivations for async_generator has
been to figure out what the semantics for native generators
should be :-). The native async generators in 3.6 use the same
implementation trick as async_generator (not entirely sure if
Yury got it from me, or if it's an independent invention), and
the yield from implementation is partly motivated as a proof of
concept / testing ground for hopefully getting it into 3.7. The
yield from semantics are pretty straightforward though, I think.<br>
>><br>
>> > As for<br>
>> > aclose/asend/athrow support, I will have to look
into that.<br>
>> ><br>
>> > Could we synchronize the implementations so that
they're compatible with<br>
>> > each other? I would've preferred there to be only
a single implementation<br>
>> > (asyncio_extras was published first, but
admittedly I didn't advertise it<br>
>> > that well) but now it'd be best if we work
together, wouldn't you agree?<br>
>><br>
>> Makes sense to me :-). I think the obvious approach
would be for async_extras to just depend on async_generator,
since AFAICT async_generator is pretty much complete, and like
you say, there's not much point in carrying around two copies of
the same thing. But if you have another suggestion I'd be
interested to hear it...<br>
><br>
> I may consider that at some point, but I'm not yet
comfortable with those extended capabilities. Meanwhile I will
add any missing functionality (asend, athrow etc.) to mine.</p>
<p dir="ltr">You could just not import yield_from_ and then you
don't have any extended capabilities... but up to you,
obviously.</p>
<p dir="ltr">> One thing I noticed is that there seems to be no
way to detect async generator functions in your implementation.
That is something I would want to have before switching.</p>
<p dir="ltr">Good point. That should be pretty trivial to add.</p>
<p dir="ltr">-n</p>
</blockquote>
<br>
</body>
</html>