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


Groups > comp.lang.python > #94924

Re: Python 3 May Become Relevant Now

References <mpmcdb$eek$1@ger.gmane.org> <427038102.1314110.1438595894636.JavaMail.root@sequans.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-08-03 02:26 -0800
Subject Re: Python 3 May Become Relevant Now
Newsgroups comp.lang.python
Message-ID <mailman.1174.1438597650.3674.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Aug 3, 2015 at 1:58 AM, 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.
>
> I don't get it.

This is where you would use optional types. Optional[List[X]] is a
shorthand for the type Union[List[X], None].

In fact static type checking can be quite useful in this sort of case.
If you return Optional[List[X]] in one place, and you have some other
method that takes in the value but simply indicates that it takes
List[X], then the static checker will flag that as an error, and
you'll know that a part of your code likely isn't handling the None
case correctly.

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


Thread

Re: Python 3 May Become Relevant Now Ian Kelly <ian.g.kelly@gmail.com> - 2015-08-03 02:26 -0800

csiph-web