[Python-ideas] Proposal: Use mypy syntax for function annotations
Cory Benfield
cory at lukasa.co.uk
Thu Aug 14 20:25:04 CEST 2014
On 14 August 2014 19:15, Steven D'Aprano <steve at pearwood.info> wrote:
> I really dislike that syntax. I dislike adding cruft like "@type" and
> ":param" into docstrings, which should be written for human readers, not
> linters.
That ship has long-since sailed. Sphinx uses exactly this :param: and
:return: syntax for its docstring parsing. It is by now a common
convention (at least, I see it all over the place in open source
code), and should not be considered a surprise. I appreciate that it
doesn't lead to clean docstrings, but I've found it leads to
docstrings that are genuinely written to be read (because they're part
of your documentation).
> So, I think this proposal might actually lead to *more* duck typing
> rather than less, since you can always turn off the type checking.
I found this conclusion impossible to understand: have I missed
something Steven? To my eyes, the fact that when run by a user who
knows nothing about the static type checker much duck typing will fail
will clearly not lead to more duck typing. It will lead either to a)
less duck typing because of all the bug reports (your code breaks
whenever I try to run it!), or b) everyone turning the static type
checker off.
That objection assumes the static checker would be on by default. If
it were off by default but available, both of these problems go away
but we're back in the situation we're in right now. In that case, I
don't see why we'd add this to CPython.
More information about the Python-ideas
mailing list