@@ -1937,10 +1937,12 @@ Example::
1937
1937
Sometimes you have a long list of parameters and specifying their
1938
1938
types in a single ``# type:`` comment would be awkward. To this end
1939
1939
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::
1944
1946
1945
1947
def send_email(address, # type: Union[str, List[str]]
1946
1948
sender, # type: str
@@ -1959,14 +1961,17 @@ Notes:
1959
1961
Python version being checked. This is necessary in order to support
1960
1962
code that straddles Python 2 and Python 3.
1961
1963
1964
+ - It is not allowed for an argument or return value to have both
1965
+ a type annotation and a type comment.
1966
+
1962
1967
- When using the short form (e.g. ``# type: (str, int) -> None``)
1963
1968
every argument must be accounted for, except the first argument of
1964
1969
instance and class methods (those are usually omitted, but it's
1965
1970
allowed to include them).
1966
1971
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``.
1970
1975
1971
1976
- When using the short form, for ``*args`` and ``**kwds``, put 1 or 2
1972
1977
stars in front of the corresponding type annotation. (As with
0 commit comments