PEP 484 was already updated to support signatures as type comments in
Python 2.7. I'd like to add two more variations to this spec, both of
which have already come up through users.

First, https://github.com/python/typing/issues/188. This augments the
format of signature type comments to allow (...) instead of an
argument list. This is useful to avoid having to write (Any, Any, Any,
..., Any) for a long argument list if you don't care about the
argument types but do want to specify the return type. It's already
implemented by mypy (and presumably by PyCharm). Example:

    def gcd(a, b):
        # type: (...) -> int
        <code here>

Second, https://github.com/python/typing/issues/186. This builds on
the previous syntax but deals with the other annoyance of long
argument lists, this time in case you *do* care about the types. The
proposal is to allow writing the arguments one per line with a type
comment on each line. This has been implemented in PyCharm but not yet
in mypy. Example:

    def gcd(
            a,  # type: int
            b,  # type: int
            ):
        # type: (...) -> int
        <code here>

In both cases we've considered a few alternatives and ended up
agreeing on the best course forward. If you have questions or feedback
on either proposal it's probably best to just add a comment to the
GitHub tracker issues.

A clarification of the status of PEP 484: it was provisionally
accepted in May 2015. Having spent close to a year pondering it, and
the last several months actively using it at Dropbox, I'm now ready to
move with some improvements based on these experiences (and those of
others who have started to use it). We already added the basic Python
2.7 compatible syntax (see thread starting at
https://mail.python.org/pipermail/python-ideas/2016-January/037704.html),
and having used that for a few months the two proposals mentioned
above handle a few corner cases that were possible but a bit awkward
in our experience.

-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to