So, if you need to change how many things you specify typing information for depending on which parser you will use, how does putting those typing information stub objects into the standard library advance anyone?


On 15 August 2014 19:11, Petr Viktorin <encukou@gmail.com> wrote:
On Fri, Aug 15, 2014 at 6:43 PM, Dennis Brakhane
<brakhane@googlemail.com> wrote:
> 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")

I really meant *only* the default. This really only works for None,
but that's a good thing, since something like:
    def foo(bar:int=''): pass
looks very suspicious. I'd be fine with the linter complaining about
foo('hello').

Of course you can always do:
    def foo(bar: (int | str)=''): pass

> 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?

If your linter can't figure it out, just specify the default's type
explicitly. Always a good thing to do when something's not immediately
obvious.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/