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


Groups > comp.lang.python > #94925

Re: Python 3 May Become Relevant Now

References <mpmcdb$eek$1@ger.gmane.org> <427038102.1314110.1438595894636.JavaMail.root@sequans.com>
Date 2015-08-03 20:28 +1000
Subject Re: Python 3 May Become Relevant Now
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1175.1438597704.3674.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web