Skip to content

Commit a1cd7fb

Browse files
ilevkivskyigvanrossum
authored andcommitted
Clarify per-argument type comments in PEP 484 (#126)
1 parent bf827dc commit a1cd7fb

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pep-0484.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,10 +1937,12 @@ Example::
19371937
Sometimes you have a long list of parameters and specifying their
19381938
types in a single ``# type:`` comment would be awkward. To this end
19391939
you may list the arguments one per line and add a ``# type:`` comment
1940-
per line. To specify the return type use the ellipsis syntax. Not
1941-
every argument needs to be given a type. A line with a ``# type:``
1942-
comment should contain exactly one argument. The type comment for the
1943-
last argument (if any) should precede the close parenthesis. Example::
1940+
per line after an argument's associated comma, if any.
1941+
To specify the return type use the ellipsis syntax. Specifying the return
1942+
type is not mandatory and not every argument needs to be given a type.
1943+
A line with a ``# type:`` comment should contain exactly one argument.
1944+
The type comment for the last argument (if any) should precede the close
1945+
parenthesis. Example::
19441946

19451947
def send_email(address, # type: Union[str, List[str]]
19461948
sender, # type: str
@@ -1959,14 +1961,17 @@ Notes:
19591961
Python version being checked. This is necessary in order to support
19601962
code that straddles Python 2 and Python 3.
19611963

1964+
- It is not allowed for an argument or return value to have both
1965+
a type annotation and a type comment.
1966+
19621967
- When using the short form (e.g. ``# type: (str, int) -> None``)
19631968
every argument must be accounted for, except the first argument of
19641969
instance and class methods (those are usually omitted, but it's
19651970
allowed to include them).
19661971

1967-
- The return type is mandatory. If in Python 3 you would omit some
1968-
argument or the return type, the Python 2 notation should use
1969-
``Any``.
1972+
- The return type is mandatory for the short form. If in Python 3 you
1973+
would omit some argument or the return type, the Python 2 notation
1974+
should use ``Any``.
19701975

19711976
- When using the short form, for ``*args`` and ``**kwds``, put 1 or 2
19721977
stars in front of the corresponding type annotation. (As with

0 commit comments

Comments
 (0)