Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; '16,': 0.03; 'interpreter': 0.05; 'sufficient': 0.05; 'generators': 0.09; 'imply': 0.09; 'warn': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'binding.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hmm.': 0.16; 'send()': 0.16; 'somewhere.': 0.16; 'subject:generator': 0.16; 'true:': 0.16; 'wrote:': 0.18; '(not': 0.18; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'second': 0.26; 'subject:/': 0.26; 'skip:" 20': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'feature': 0.29; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'enabled': 0.31; 'steven': 0.31; 'values.': 0.31; 'quite': 0.32; 'used,': 0.33; 'actual': 0.34; 'except': 0.35; 'form.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'yield': 0.36; 'possible': 0.36; 'two': 0.37; 'pm,': 0.38; 'expect': 0.39; 'extremely': 0.39; 'though,': 0.39; 'sure': 0.39; 'skip:u 10': 0.60; 'expression': 0.60; 'tell': 0.60; 'first': 0.61; 'name': 0.63; 'different': 0.65; 'between': 0.67; 'mar': 0.68; '2015': 0.84; 'distinguish': 0.84; 'so...': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=pNrnTTFlxF3R7jvy+LuLqw6akqsNvmdac/jGOsNs1BQ=; b=OWLgYYuQeFrsqdzztiRlGUmzwYSAxwXmodp3ugPfyg9zXp0Pnv3M03i+fvNPu1dEBW pqxt+eJcF61I0AZAsKxqRuJohsnqDg9x1m+LF9ZP3dkeBdQfkUO3UyALyohd6UQCRYPo OgqOC+gZFDyOJKnMJOIWfzIJNYkr3Ghr62YaLYmrGke0t4wqm44nVQq0QkALhLZ9L+e5 Uh4V4R6wQuyhzrdDdPLfXc5RI5FcksjtPQZXkIpprqwuDImLCkKvha3OXU/EaYqj5RTE 8qFxFqlXNs2IdkBlx4v/rZK0MlCLIdL9c3M2+IUuCWrgdKl5stnVHF5rwKLnuWDbbV5t 6QNg== MIME-Version: 1.0 X-Received: by 10.107.134.219 with SMTP id q88mr61853858ioi.27.1426496302219; Mon, 16 Mar 2015 01:58:22 -0700 (PDT) In-Reply-To: <55069623$0$12901$c3e8da3$5496439d@news.astraweb.com> References: <5501be8b$0$13006$c3e8da3$5496439d@news.astraweb.com> <874mpnp6nv.fsf@elektro.pacujo.net> <87y4mznmj8.fsf@elektro.pacujo.net> <55062bda$0$12998$c3e8da3$5496439d@news.astraweb.com> <87egopmn4z.fsf@elektro.pacujo.net> <55069623$0$12901$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 16 Mar 2015 19:58:22 +1100 Subject: Re: generator/coroutine terminology From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1426496304 news.xs4all.nl 2923 [2001:888:2000:d::a6]:33966 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87538 On Mon, Mar 16, 2015 at 7:36 PM, Steven D'Aprano wrote: > I expect that the interpreter can tell the difference between > > yield spam > > and > > x = yield spam > > and only allow send(), close() and throw() on generators which include the > second form. If it can't, then that's a limitation, not a feature to be > emulated. > Hmm. That would imply that an expression is different if it's used somewhere. In Python, there's no difference between these two function calls: x = func(1,2,3) func(1,2,3) except for the actual name binding. If a yield expression enabled send() if and only if its return value were used, then it would be extremely surprising: def use_and_discard(): while True: _ = (yield 1) def just_yield(): while True: yield 1 So... I can send into the first but not into the second? That said, though, it would be quite reasonable for a *linter* to warn you about sending into a generator that never uses sent values. With a good type inference system (not sure if MyPy is sufficient here), it would be possible to distinguish between those two functions and declare that the first one has the return type "sendable_generator" and the second one "nonsendable_generator", and give a warning if you send into the latter. But I don't think that's the language's job. ChrisA