parent
93111da051
commit
5f30d8f81a
27
pep-0484.txt
27
pep-0484.txt
|
@ -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
|
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.
|
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
|
The type of class objects
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
Loading…
Reference in New Issue