Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'newbie': 0.05; 'compiler': 0.07; 'nested': 0.07; 'suppose': 0.07; '%s"': 0.09; 'raises': 0.09; 'runtime': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'def': 0.12; '(code,': 0.16; 'clause.': 0.16; 'constructs': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'none.': 0.16; 'subject:between': 0.16; 'subject:tasks': 0.16; 'tripped': 0.16; 'unexpected': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; 'result.': 0.19; 'later': 0.20; 'cc:addr:python.org': 0.22; 'error': 0.23; 'byte': 0.24; "shouldn't": 0.24; 'skip:l 30': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'raise': 0.29; 'reporting': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'commonly': 0.31; 'fri,': 0.33; 'style': 0.33; 'subject:the': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'useful': 0.36; 'subject:?': 0.36; 'clear': 0.37; 'branch': 0.38; 'pm,': 0.38; 'even': 0.60; 'dave': 0.60; 'improved': 0.60; 'most': 0.60; "you're": 0.61; 'kind': 0.63; 'such': 0.63; 'more': 0.64; 'due': 0.66; 'between': 0.67; 'therefore': 0.72; '2015': 0.84; 'checkin': 0.84; 'confusing': 0.84; 'detecting': 0.84; 'angel': 0.91; 'dealt': 0.91; '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=cJHweM0YW6gJs8itxiUQg3P6m2DV6YEIsC5aC8PYUJ8=; b=x8JBPEq/otY75b+oyw41m7hRbYRK6HC+rOXzl2DAzQ6/PTiRIlhU0yewOSylJPjdtD fSjYlkp9onZbDm5I9ZzABw/QNLRbiJn1UjtzHFi7RihpuKeeIKPy/k0B33OSj8k/+kqW RaFRo1qRSHIQlJ+v04NTjZzr0v4GEmtygWteFG+fKVQQxeXYPoh4UW6jjos4XAtmGYf3 8nj4pKlQ63WOZZtuAhrk8YfAv5NRbZtjQ+PnySGgE/EPWZe9O2mLkgMPZ/jta+3gbycM cETZ21J3O71+PoyW3/Yz0DvF95ZoDo2VkRl/KmyftQOjpOfeVcwXLOs9pMefrc43EPHP uYbw== MIME-Version: 1.0 X-Received: by 10.43.96.10 with SMTP id ce10mr3837668icc.59.1431090133669; Fri, 08 May 2015 06:02:13 -0700 (PDT) In-Reply-To: <554CA3B1.1080309@davea.name> References: <344fd8f6-75c1-4b7d-888d-c5c9d4498ec3@googlegroups.com> <878ud27waw.fsf@elektro.pacujo.net> <4ea2d5ac-8c19-4a53-9a09-fe6dbe4a52bd@googlegroups.com> <5549ab43$0$11108$c3e8da3@news.astraweb.com> <554CA3B1.1080309@davea.name> Date: Fri, 8 May 2015 23:02:13 +1000 Subject: Re: asyncio: What is the difference between tasks, futures, and coroutines? 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.20+ 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431090137 news.xs4all.nl 2922 [2001:888:2000:d::a6]:33160 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90165 On Fri, May 8, 2015 at 9:53 PM, Dave Angel wrote: > One thing newbies get tripped up by is having some path through their code > that doesn't explicitly return. And in Python that path therefore returns > None. It's most commonly confusing when there are nested ifs, and one of > the "inner ifs" doesn't have an else clause. > > Anyway, it's marginally more useful to that newbie if the compiler would > produce an error instead of later seeing a runtime error due to an > unexpected None result. > > I don't think Python would be improved by detecting such a condition and > reporting on it. That's a job for a linter, or a style guide program. They're not hard for linters to notice. After all, there's a clear difference of intent between "return" (or just falling off the end of the function) and "return None", even though they compile to the same byte code. Though if you start enforcing that in your checkin policy, you might have to deal with this kind of thing: def raise_with_code(code): raise SpamError("Error %d in spamination: %s" % (code, errortext.get(code, ""))) def spaminate_text(f): rc = low_level_spamination_function(f) if not rc: return low_level_get_spamination_result() raise_with_code(rc) Clearly one branch returns a value... but figuring out that the other one always raises isn't easy. (Though I suppose in this case it could be dealt with by having a function that constructs the error, and then you "raise make_spam_error(rc)" instead.) You're definitely right that Python shouldn't check for it. ChrisA