Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pep-0484.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,33 @@ the other hand, when a value has type ``Any``, the type checker will
allow all operations on it, and a value of type ``Any`` can be assigned
to a variable (or used as a return value) of a more constrained type.

A function parameter without an annotation is assumed to be annotated with
``Any``. If a gneric type is used without specifying type parameters,
they assumed to be ``Any``::

from typing import Mapping

def use_map(m: Mapping) -> None: # Same as Mapping[Any, Any]
...

This rule also applies to ``Tuple``, in annotation context it is equivalent
to ``Tuple[Any, ...]`` and, in turn, to ``tuple``. As well, a bare
``Callable`` in an annotation is equivalent to ``Callable[[...], Any]`` and,
in turn, to ``collections.abc.Callable``::

from typing import Tuple, List, Callable

def check_args(args: Tuple) -> bool:
...

check_args(()) # OK
check_args((42, 'abc')) # Also OK
check_args(3.14) # Flagged as error by a type checker

# A list of arbitrary callables is accepted by this function
def apply_callbacks(cbs: List[Callable]) -> None:
...


The type of class objects
-------------------------
Expand Down