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

Chris Angelico rosuav at gmail.com
Wed Aug 3 16:10:21 EDT 2016


On Thu, Aug 4, 2016 at 3:35 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>> But, again, real problems arise when the type of an *initialized*
>> instance must always be some data structure (and not None), but you
>> can't come up with a reasonable default initializer that has the
>> proper type.
>
> 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.
>
> Disadvantages:
>
> - Javascript programmers will think you can write `print(result)` and
> get "undef" (or similar);
> - requires a new keyword.

Python already has a way of spelling "make this no longer be defined":

del result

Not sure that helps, though, because it too will NameError if it
doesn't already exist :)

ChrisA


More information about the Python-ideas mailing list