[Python-Dev] Type hints -- a mediocre programmer's reaction (original) (raw)

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


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