On 17Jun2018 11:10, Rick Johnson <rantingrickjohn...@gmail.com> wrote:
Steven D'Aprano wrote:
But the human reader, linters, IDEs and editors can
associate it with the name it annotates, and use it as a
hint as to what is intended to happen, and flag any
discrepancies.
And each of these could have done the same with a "type-hint
comment". But oh no, that would be too easy! And the whole
point here is to cause a big fat ruckus? Isn't it, Mr.
D'Aprano?
No, it is so that there can be an agreed syntax for this stuff rather than a
billion funky special comments, and also so that _compiled_ python can be
inspected for type hints because they survive that step. This makes for machine
inspectable hints very easily, and that is a boon for linters.
Another advantage of type hints being part of the syntax is that
invalid/mistyped type hints can be caught by the parser. If they're just
special comments then linters _might_ see them and complain, or equally they
might say "this comment isn't a valid type hint, so it is an ordinary comment",
silently ignoring it. Thus weakening the lint.
As for the runtime ignoring them: they can't accomodate all situations in a
dynamic language, and type checking would impose a performance penalty for no
semantic effect.
Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list