[Python-Dev] Type hints -- a mediocre programmer's reaction

Paul Moore p.f.moore at gmail.com
Tue Apr 21 15:20:55 CEST 2015


On 21 April 2015 at 13:47, Steven D'Aprano <steve at pearwood.info> wrote:
> On Tue, Apr 21, 2015 at 11:56:15AM +0100, Rob Cliffe wrote:
>
>>         (Adding a type hint that restricted the argument to say a
>> sequence of numbers turns out to be a mistake.
>
> Let's find out how big a mistake it is with an test run.
>
> py> def sorter(alist: List[int]) -> List[int]:
> ...     return sorted(alist)
> ...
> py> data = (chr(i) + 'ay' for i in range(97, 107))
> py> type(data)
> <class 'generator'>
> py> sorter(data)
> ['aay', 'bay', 'cay', 'day', 'eay', 'fay', 'gay', 'hay', 'iay', 'jay']
>
>
> When we say that type checking is optional, we mean it.

That's a very good point - although I have to say that I sort of feel
like I'm cheating doing that. It doesn't matter how many times you say
"optional", it does still feel like it's wrong, in basically the same
way as using undocumented methods on a class, etc.

Conceded, type checking is optional. But that message seems to be
failing to get through. It's not a technical thing, it's a PR issue.
Which is *very* close to meaning that the problem is FUD, but less in
the sense of "people deliberately spreading FUD" as "people being
worried, not understanding the proposal, and not being sure how type
hints will work in practice".

I'm reasonably willing to just accept that the PEP will be getting
implemented, and to wait and see how things turn out. But my fear,
uncertainty and doubt remain. I'll try not to spread them, though.

>> You see where I'm going with this - adding type hints to Python feels a
>> bit like painting feet on the snake.
>
> Pythons are one of the few snakes which have vestigal legs:
>
> http://en.wikipedia.org/wiki/Pelvic_spur

LOL, instant win :-)

Paul


More information about the Python-Dev mailing list