8000 Clarify meaning of bare Tuple, etc. (#110) · python/peps@5f30d8f · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f30d8f

Browse files
ilevkivskyigvanrossum
authored andcommitted
Clarify meaning of bare Tuple, etc. (#110)
Fixes python/typing#284
1 parent 93111da commit 5f30d8f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pep-0484.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,33 @@ the other hand, when a value has type ``Any``, the type checker will
10191019
allow all operations on it, and a value of type ``Any`` can be assigned
10201020
to a variable (or used as a return value) of a more constrained type.
10211021

1022+
A function parameter without an annotation is assumed to be annotated with
1023+
``Any``. If a gneric type is used without specifying type parameters,
1024+
they assumed to be ``Any``::
1025+
1026+
from typing import Mapping
1027+
1028+
def use_map(m: Mapping) -> None: # Same as Mapping[Any, Any]
1029+
...
1030+
1031+
This rule also applies to ``Tuple``, in annotation context it is equivalent
1032+
to ``Tuple[Any, ...]`` and, in turn, to ``tuple``. As well, a bare
1033+
``Callable`` in an annotation is equivalent to ``Callable[[...], Any]`` and,
1034+
in turn, to ``collections.abc.Callable``::
1035+
1036+
from typing import Tuple, List, Callable
1037+
1038+
def check_args(args: Tuple) -> bool:
1039+
...
1040+
1041+
check_args(()) # OK
1042+
check_args((42, 'abc')) # Also OK
1043+
check_args(3.14) # Flagged as error by a type checker
1044+
1045+
# A list of arbitrary callables is accepted by this function
1046+
def apply_callbacks(cbs: List[Callable]) -> None:
1047+
...
1048+
10221049

10231050
The type of class objects
10241051
-------------------------

0 commit comments

Comments
 (0)
0