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

Florian Bruhin me at the-compiler.org
Thu Apr 23 11:01:23 CEST 2015


* Wolfgang Langner <tds333+pydev at gmail.com> [2015-04-23 10:43:52 +0200]:
> 2. Using it in the language as part of the function signature, my first
> thought was oh good, then I changed my mind
>    to: oh it can be very ugly and unreadable, it is the wrong place.
>    Now I am against it, best is, if I have to specify type signatures, do
> it in one place, keep them up to date.
>    Most of the time this is the documentation. Why not use the docstring
> with a standard type specifier for this.
>    Suggested here:
> http://pydev.blogspot.de/2015/04/type-hinting-on-python.html

While I happen to agree with you (but I'm happy with both variants
really), I think that's a thing which has definitely been decided
already.

The idea is also listed in the PEP:

https://www.python.org/dev/peps/pep-0484/#other-backwards-compatible-conventions

    Docstrings. There is an existing convention for docstrings, based
    on the Sphinx notation ( :type arg1: description ). This is pretty
    verbose (an extra line per parameter), and not very elegant. We
    could also make up something new, but the annotation syntax is
    hard to beat (because it was designed for this very purpose).

> For nearly every function I have written, there is a docstring and most of
> the time also a type specified.
> But if I must provide all this in a second place it is not the right way to
> go. Over time normally one place misses some changes and is wrong.

It seems there's an extension for Sphinx already to use type
annotations:

https://pypi.python.org/pypi/sphinx-autodoc-annotation

It seems to be older than PEP 484 (December 2013), so I hope it'll be
updated or already work well with the ideas in the PEP.

> Also ask why no one used type specifier, they are possible since Python 3.0
> ?
> Because it is the wrong way for Python.

Well, except that Sphinx extension, and MyPy, and MicroPython, and a
thing which already exists for run-time type checking[1] and probably
a whole lot more.

The whole *reason* for PEP 484 (at least from my perspective) is to
have a common base for the existing usages of type annotations.

Florian

[1] https://github.com/ceronman/typeannotations

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150423/ec89f954/attachment-0001.sig>


More information about the Python-Dev mailing list