[Python-ideas] Optional static typing -- the crossroads

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Aug 16 01:57:48 CEST 2014


Petr Viktorin wrote:
> Instead of
> 
>     def optional(t):
>         return t | None
> 
> it's now:
> 
>     def optional(t):
>         if t is None:
>             return t
>         else:
>             return t | None

I don't think so. Code that's manipulating types shouldn't be
using None as a stand-in for NoneType in the first place.

Think of it this way: None is *not* a type, just a special-case
value of x in "<type> | x". So optional(None) is an error, just
as much as optional(42) would be.

-- 
Greg


More information about the Python-ideas mailing list