@@ -16,10 +16,22 @@ Resolution:
16
16
Abstract
17
17
========
18
18
19
- This PEP introduces a standard syntax for type hints using annotations
20
- (PEP 3107) on function definitions. For example, here is a simple
21
- function whose argument and return type are declared in the
22
- annotations::
19
+ PEP 3107 introduced syntax for function annotations, but the semantics
20
+ were deliberately left undefined. There has now been enough 3rd party
21
+ usage for static type analysis that the community would benefit from
22
+ a standard vocabulary and baseline tools within the standard library.
23
+
24
+ This PEP introduces a provisional module to provide these standard
25
+ definitions and tools, along with some conventions for situations
26
+ where annotations are not available.
27
+
28
+ Note that this PEP still explicitly does NOT prevent other uses of
29
+ annotations, nor does it require (or forbid) any particular processing
30
+ of annotations, even when they conform to this specification. It
31
+ simply enables better coordination, as PEP 333 did for web frameworks.
32
+
33
+ For example, here is a simple function whose argument and return type
34
+ are declared in the annotations::
23
35
24
36
def greeting(name: str) -> str:
25
37
return 'Hello ' + name
@@ -29,6 +41,9 @@ While these annotations are available at runtime through the usual
29
41
Instead, the proposal assumes the existence of a separate off-line
30
42
type checker which users can run over their source code voluntarily.
31
43
Essentially, such a type checker acts as a very powerful linter.
44
+ (While it would of course be possible for individual users to employ
45
+ a similar checker at run time for Design By Contract enforcement or
46
+ JIT optimization, those tools are not yet as mature.)
32
47
33
48
The proposal is strongly inspired by mypy [mypy]_. For example, the
34
49
type "sequence of integers" can be written as ``Sequence[int]``. The
0 commit comments