<div dir="ltr"><div class="gmail_extra">Hi Koos,</div><div class="gmail_extra"><br><div class="gmail_quote">2015-05-05 15:55 GMT+02:00 Koos Zevenhoven <span dir="ltr"><<a href="mailto:koos.zevenhoven@aalto.fi" target="_blank">koos.zevenhoven@aalto.fi</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">With this addition to Python, one could write libraries that work both async and non-async. When await is not inside async def, one would expect it to potentially do blocking IO, just like an await inside async def would suggest that there is a yield/suspend somewhere in there.</blockquote></div><br><br>To be honest with you, I'd this type of ideas back in my mind, but for now, I've no suggestion to avoid end-developer nor low-developer nightmares.</div><div class="gmail_extra"><br>For example, we may detect if it's async or not if you have: result = await response.payload() or result = response.payload()</div><div class="gmail_extra">The issue I see with that and certainly already explained during PEP492 discussions, is that it will be difficult for the developer to spot where he is forgotten await keyword, because he won't have errors.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Moreover, in the use cases where async is less efficient that sync, it should be interesting to be possible, maybe with a context manager to define a block of code where all await are in fact sync (without to use event loop). But, even if a talentuous low-developper find a solution to implement this idea, because I'm not sure it's technically possible, in fact it will more easier even for end-developers to use the sync library version of this need.</div><div class="gmail_extra"><br></div><div class="gmail_extra">FYI, I've made an yocto library for my company where I need to be sync for some use cases and async for some other use cases.</div><div class="gmail_extra">For the sync and async public API where the business logic behind most functions are identical, I've followed the same pattern as in Python-LDAP: <a href="http://www.python-ldap.org/doc/html/ldap.html#sending-ldap-requests">http://www.python-ldap.org/doc/html/ldap.html#sending-ldap-requests</a></div><div class="gmail_extra">I've postfixed all sync functions by "_s".</div><div class="gmail_extra"><br></div><div class="gmail_extra">For a more complex library, it may possible to have two differents classes with explicit names.</div><div class="gmail_extra"><br></div><div class="gmail_extra">At least to me, it's enough to work efficiently, explicit is better than implicit ;-)</div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div>--<br><div style="font-size:small"><div>Ludovic Gasc (GMLudo)</div></div><div style="font-size:small"><a href="http://www.gmludo.eu/" target="_blank">http://www.gmludo.eu/</a></div></div></div></div></div>
</div></div>