[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484

Chris Barker chris.barker at noaa.gov
Wed Aug 3 14:33:34 EDT 2016


On Wed, Aug 3, 2016 at 10:35 AM, Steven D'Aprano <steve at pearwood.info>
wrote:

> Again, playing Devil's Advocate... maybe we want a concept of
> "undefined" like in Javascipt.
>
>     result: Type = undef
>
> which would make it clear that this is a type declaration, and that
> result is still undefined.
>

I like this -- and we need to change the interpreter anyway. I take it this
would be a no-op at run time?


Though I'm still on the fence -- it's a common idiom to use None to mean
undefined.

For example, I at least, always thought is was better style to do:

class Something():
     an_attribute = None

and then:

if self.an_attribute is None:
    ....

Than not predefine it, and do:

if not hasattr(self, 'an_attribute'):
   ....

granted, I only do that for class (or instance) attributes in real code,
not all names.

So do we really need to support "this variable can be undefined, but if it
is defined in can NOT be None?

Are there really cases where a variable can't be None, but there is NO
reasonable default value?

Or are folks hitting a limitation in the type checker's ability to deal
with None?


> Disadvantages:
>
> - Javascript programmers will think you can write `print(result)` and
> get "undef" (or similar);
>

Do we care about that????

BTW, does JS have a None? or is 'undef' its None?

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160803/5a41e961/attachment-0001.html>


More information about the Python-ideas mailing list