Re: Type hints -- a mediocre programmer's reaction
[Posted May 6, 2015 by jake]
| From: |
| Chris Angelico <rosuav-AT-gmail.com> |
| To: |
| |
| Subject: |
| Re: Type hints -- a mediocre programmer's reaction |
| Date: |
| Tue, 21 Apr 2015 19:10:40 +1000 |
| Message-ID: |
| <CAPTjJmqzFfLXH-UToA5iM_Pt-ooV6qJFiQ4gR9+QXMca5jQXCg@mail.gmail.com> |
| Cc: |
| Python Dev <python-dev-AT-python.org> |
On Tue, Apr 21, 2015 at 6:58 PM, Cory Benfield <cory@lukasa.co.uk> wrote:
> On 21 April 2015 at 01:45, Chris Angelico <rosuav@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