Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94925 > unrolled thread

Re: Python 3 May Become Relevant Now

Started byChris Angelico <rosuav@gmail.com>
First post2015-08-03 20:28 +1000
Last post2015-08-03 20:28 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python 3 May Become Relevant Now Chris Angelico <rosuav@gmail.com> - 2015-08-03 20:28 +1000

#94925 — Re: Python 3 May Become Relevant Now

FromChris Angelico <rosuav@gmail.com>
Date2015-08-03 20:28 +1000
SubjectRe: Python 3 May Become Relevant Now
Message-ID<mailman.1175.1438597704.3674.python-list@python.org>
On Mon, Aug 3, 2015 at 7:58 PM, Jean-Michel Pichavant
<jeanmichel@sequans.com> wrote:
> But if I get things right, with python 3.5 type hint checker, I'd be screwed, as it is spefificaly designed to track this kind of "problem".
> What's the use of None then ? Any method returning None can only return None or suffer the type checker retribution.

1) Python 3.5 will not include a type checker. All it'll include is
enough stubs that your code will run correctly; plus it has a set of
specifications for how third-party checkers should be advised, which
means you'll be able to use any such checker with the same code. But
nothing will happen till you actually run such a checker.

2) Since "returns X or None" is such a common thing, it's very easy to
spell. More complicated things are possible, too, but less cleanly.
Python still allows you to return anything from anything, and that
isn't changing; but there are a number of common cases - for instance,
this function might always return a number, or maybe it'll always
return a dictionary that maps strings to integers. Those are easily
spelled.

So no, a method that can return None is most definitely *not* required
to return None in all cases. Although you may find that some linters
and code style guides object to code like this:

def some_function(some_arg):
    if some_condition:
        return some_expression

where one branch has an explicit 'return' and another doesn't. That's
a quite reasonable objection, and an explicit "return None" at the end
will suppress the warning, by being more explicit that this might
return this or that.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web