[Python-ideas] Structural type checking for PEP 484

Stephen J. Turnbull stephen at xemacs.org
Thu Sep 17 03:04:53 CEST 2015


Sven R. Kunze writes:

 > Do you know what makes me sad? If you do that for this function but 
 > don't do it for another what is the guideline then? Python Zen tells us 
 > to have one obvious way to do sth. At least for me, it's not obvious 
 > anymore when to annotate and when not to annote. Just a random guess 
 > depending on the moon phase? :(

No.  There's a simple rule: if it's obvious to you that type
annotation is useful, do it.  If it's not obvious you want it, you
don't, and you don't do it.  You obviously are unlikely to do it for
some time, if ever.  Me too.

But some shops want to use automated tools to analyze these things,
and I don't see why there's a problem in providing a feature that
makes it easier for them to do that.

 > Btw. I can tell the same anecdote when switching from C/C++/C#/Java to 
 > Python. It was like a liberation---no explicit type declarations 
 > anymore. I was baffled and frightened the first week using it. But I 
 > love it now and I don't want to give that freedom up. Maybe, that's why 
 > I am reluctant to use it in production.

So don't, nothing else in the language depends on type annotation or
on running a type checker for that matter.  What's your point?  That
you'll have to read them in the stdlib?  Nope; the stdlib will use
stubfiles where it uses type annotations at all for the foreseeable
future.  That your employer might make you use them?  That's the
nature of employment.  And if you can't convince your boss that
annotations have no useful role in a program written in good style,
why would you expect to convince us?



More information about the Python-ideas mailing list