[Python-Dev] Type hints -- a mediocre programmer's reaction
Chris Angelico
rosuav at gmail.com
Tue Apr 21 11:10:40 CEST 2015
On Tue, Apr 21, 2015 at 6:58 PM, Cory Benfield <cory at lukasa.co.uk> wrote:
> On 21 April 2015 at 01:45, Chris Angelico <rosuav at gmail.com> wrote:
>> When you're writing a library, it can be a great help to provide type
>> annotations, because every application that uses your library can
>> benefit.
>
> It can be a great help to whom? Not to me (the library author),
> because I can't use them in my library code, because I have to support
> 2.7. That's by no means a bad thing (after all, most libraries are
> written to help others), but I found it really unclear who was being
> advantaged here.
Mainly application users get the benefit, I expect. But I may be wrong.
> ... That's got *nothing* on the type of the `files`
> argument, which is the most incredibly polymorphic argument I've ever
> seen: the best I can work out it would be:
>
> Optional[
> Union[
> Mapping[
> basestring,
> Union[
> Tuple[basestring, Optional[Union[basestring, file]]],
> Tuple[basestring, Optional[Union[basestring, file]],
> Optional[basestring]],
> Tuple[basestring, Optional[Union[basestring, file]],
> Optional[basestring], Optional[Headers]]
> ]
> ],
> Iterable[
> Tuple[
> basestring,
> Union[
> Tuple[basestring, Optional[Union[basestring, file]]],
> Tuple[basestring, Optional[Union[basestring,
> file]], Optional[basestring]],
> Tuple[basestring, Optional[Union[basestring,
> file]], Optional[basestring], Optional[Headers]]
> ]
> ]
> ]
> ]
At this point, you may want to just stop caring about the exact type.
Part of the point of gradual typing is that you can short-cut a lot of
this. And quite frankly, this isn't really helping anything. Just skip
it and say that it's Union[Mapping, Iterable, None].
ChrisA
More information about the Python-Dev
mailing list