Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102303
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Kevin Conway <kevinjacobconway@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Cannot step through asynchronous iterator manually |
| Date | Sat, 30 Jan 2016 13:18:11 +0000 |
| Lines | 59 |
| Message-ID | <mailman.129.1454159903.2338.python-list@python.org> (permalink) |
| References | <n8hjmt$b8n$1@ger.gmane.org> <CALwzid=sSDSm8hdAN+ORJ54A_jEu9Wc8103iqGKAah8mrj-TXw@mail.gmail.com> <n8hrs1$orn$1@ger.gmane.org> <CAPTjJmoAmVNTCKq7QYaDRNQ67Gcg9TxSXYXCrY==S9Djjna_rA@mail.gmail.com> <n8i4j9$lb4$1@ger.gmane.org> <CAGqiJR8yUdd1u7j0YHS-He_v4uUT-ui=PpiX=n_G=ntt8ZnTpg@mail.gmail.com> <CAKF=+diQQS_FZxHjMwfx1_b1nz7eFdaUbqpUn9nxELC8SHfWpA@mail.gmail.com> <CAPTjJmqmXgjCNzBibTJHiSKJ_3GbggEjALXTiZ=GoPKOsbt0Gw@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de WuGJ/4TtJ7md8NlyEAE5UgSn511/Qlg12eSYMzNlL3SA== |
| Return-Path | <kevinjacobconway@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'yet.': 0.03; 'wrapper': 0.07; 'cc:addr:python-list': 0.09; 'default:': 0.09; 'situation.': 0.09; 'snippet': 0.09; 'assume': 0.11; 'jan': 0.11; 'def': 0.13; '2016': 0.16; 'async': 0.16; 'cc:name:python': 0.16; 'docstring': 0.16; 'exposes': 0.16; 'fancy': 0.16; 'iterable': 0.16; 'iterables': 0.16; 'iterator': 0.16; 'object()': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sentinel': 0.16; 'updates:': 0.16; 'value:': 0.16; 'wrote:': 0.16; '>': 0.18; 'email addr:gmail.com>': 0.18; 'variable': 0.18; 'library': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'names.': 0.22; 'kevin': 0.23; 'sat,': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'chris': 0.26; 'equivalent': 0.27; 'least': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'interface': 0.29; 'looks': 0.29; 'raise': 0.29; 'url:mailman': 0.30; 'code': 0.30; 'fixed': 0.31; 'noticed': 0.32; 'url:python': 0.33; 'curious': 0.33; 'url:listinfo': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'next': 0.35; 'question,': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'one,': 0.37; 'list.': 0.37; 'received:209': 0.38; 'rather': 0.39; 'url:mail': 0.40; 'address': 0.61; 'avoid': 0.61; 'default': 0.61; '30,': 0.63; 'improved': 0.63; 'believe': 0.66; 'today.': 0.67; 'await': 0.76; 'chrisa': 0.84; 'idiom': 0.84; 'original.': 0.84; 'ultimately,': 0.84; 'url:show': 0.84; 'comment.': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-type; bh=RNyBKgUtl0TrIrWlC26UyeCzz0Kkox1uRSyusHkBIZw=; b=o5xSbXGmqeC3Bbfdi9KOpciXbPuC7OQkgi7vTD9QuRd/xskJHoWliHaA6q8zFHR6Cy ayW+ub731ulvXrIsJYv9nBJQ8fvremDI5aRDjkUVGqDDnNcwatWxJy7HBr+HhZsSUoUb hzrNQz2L6iqRkGDk6kffLsVD/SMFGnk/QA/kD3s0Q9lduulcj18dGupYtDocTdnCwaLX zOOoE1yEomLOoIEDA5iuquie7koTAs317AzdrGzLnsm+Sa0V+3hFsbrSvyafZzrdIIXM PpSfbNWs0D/A7OCpg0R6EOnm/fVTcV9JPLSWtvhOxUqyXJGFMQD4GplDTHb/y/9v4KdJ 3sAQ== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-type; bh=RNyBKgUtl0TrIrWlC26UyeCzz0Kkox1uRSyusHkBIZw=; b=ajTNu8qfF4BLINAA3X9chqfizas0sNvKwYMTCKsy+58vc6B2ozRvey50QWSTIuEX/3 E//2SYHaBOwUfuCP2WoAH+J/eeav5OilIxYceXDYE+DithhELxmeq4hbv4RKsGPDX5UL 0rH4Mh4Sh1SPNwoDFfZJqozfDUp7ZtPRaU7L1xhqs+q0RUSLnzeSMkuOpt76W7phaxy5 M01hFJ8pn6HDWpB83CpBqLvfNdmg2SGnqMw48GCFslv7fl6PWFjqitTNcVIv/oKTXQuH 2aIGt0bf9uEqaz7NglPmV0oT7DDL2p5ftvD/K4+VmDEEZqls6IIdnjqMD6wPsOpoh/1h lVQQ== |
| X-Gm-Message-State | AG10YORg4fmvYvzZjczcQ9g3AcYtjLOx9rCfGKzElk50ShNLfZ900vSL4RohxrtSRIdQqUWaqD/qyiJhoZQNQA== |
| X-Received | by 10.107.35.65 with SMTP id j62mr6798436ioj.30.1454159901393; Sat, 30 Jan 2016 05:18:21 -0800 (PST) |
| In-Reply-To | <CAPTjJmqmXgjCNzBibTJHiSKJ_3GbggEjALXTiZ=GoPKOsbt0Gw@mail.gmail.com> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.20+ |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:102303 |
Show key headers only | View raw
> Any particular reason not to use the classic sentinel object model? None that I can remember. I would use the sentinel pattern if I were writing it again today. > Also curious is that you raise a new StopAsyncIteration from the original one, rather than just reraising the original. I assume there's a reason for that, but it doesn't have a comment. I think I was just playing around with the new syntax. I also just noticed that there is an inconsistent use of the terms iterator and iterable in the docstring and variable names. The function looks much improved after updates: https://bpaste.net/show/14292d2b4070. Thanks for calling that out. Note to self: Review old code before copy/pasta into the mail list. On Sat, Jan 30, 2016 at 6:57 AM Chris Angelico <rosuav@gmail.com> wrote: > On Sat, Jan 30, 2016 at 11:35 PM, Kevin Conway > <kevinjacobconway@gmail.com> wrote: > > To address the original question, I don't believe a next() equivalent for > > async iterables has been added to the standard library yet. Here's an > > implementation from one of my projects that I use to manually get the > next > > value: https://bpaste.net/show/e4bd209fc067. It exposes the same > interface > > as the synchronous next(). Usage: > > > > await anext(some_async_iterator) > > > > Ultimately, it's a fancy wrapper around the original snippet of 'await > > iterator.__anext__()'. > > Curious idiom for the one-or-two-arg situation. Any particular reason > not to use the classic sentinel object model? > > _SENTINEL = object() > async def anext(iterable, default=_SENTINEL): > ... > if default is not _SENTINEL: > return default > > Or if you want to avoid that, at least take iterable as a fixed arg: > > async def anext(iterable, *default): > if len(default) > 1: TypeError > ... > if default: return default[0] > > Also curious is that you raise a new StopAsyncIteration from the > original one, rather than just reraising the original. I assume > there's a reason for that, but it doesn't have a comment. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list >
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Cannot step through asynchronous iterator manually Kevin Conway <kevinjacobconway@gmail.com> - 2016-01-30 13:18 +0000
csiph-web