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

Dennis Brakhane brakhane at googlemail.com
Fri Aug 15 18:43:02 CEST 2014


On 15.08.2014 17:42, Petr Viktorin wrote:
>
> The common use is not all that concise:
>     def foo(bar: int | None=None): pass
>
> Or alternatively it could be:
>     def foo(bar: int=None): pass
> if the default was automatically allowed.
(Assuming you mean "the type of the default")

While I like the second form a bit more, it kinda goes against "explicit
is better than implicit".

Also, if I change the default value from None to 42, I've either changed
the allowable types,
or need to remember to turn "bar: int=None" into "bar: int|None = 42".

Furthermore, what should happen in the following case:


# no annotations here
def foo(): ...

def bar(evil: int = foo()): ...


Should this be disallowed, as the type checker will not be able to know
what type foo is? Should it just assume int?
And in the latter case, what should happen if foo now gains a "-> float"
annotation?



More information about the Python-ideas mailing list