[Python-ideas] Proposal: Use mypy syntax for function annotations

Dennis Brakhane brakhane at googlemail.com
Fri Aug 15 12:02:21 CEST 2014


Am 15.08.2014 11:11, schrieb Stephen J. Turnbull:
> Have you never written code that was perfectly sound for your purpose,
> but could be used in other contexts according to ducktyping?  Are you
> *sure* that it is valid in those other contexts?  (Think sum vs.
> math.fsum -- accuracy matters.)
>
Well, if someone uses my frobnicate method that I intended to be only
usable by lists, but
he uses it with generators, it's his responsibility to write a unit test
for his code (which he
should do anyway). Therefore he's responsible for guaranteeing that his
code continues to work,
and a linter should not tell him "you can't do that, the author hasn't
thought of that". At least
I should be able to silence the warning *once* and for all. Furthermore,
I want my IDE to suggest me the frobnicate
method even if I'm working with generators, so there should be a way for
me to tell the linter and IDE
"frobnicate takes an iterable, ignore the silly original annotation"

Unit testing your own code is the only way you can "guarantee" that your
code runs correctly.

After all, even if you use my frobnicate method only with lists, you
will still have to write a test, maybe I
introduce a subtle bug in the new version of my library.


More information about the Python-ideas mailing list