On Mon, Aug 3, 2015 at 7:58 PM, Jean-Michel Pichavant <jeanmic...@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 -- https://mail.python.org/mailman/listinfo/python-list