@@ -18,11 +18,13 @@ Abstract
18
18
This PEP introduces a standard syntax for type hints using annotations
19
19
on function definitions.
20
20
21
+ The proposal is strongly inspired by mypy [mypy]_.
22
+
21
23
22
24
Rationale and Goals
23
25
===================
24
26
25
- PEP 3107 [# pep-3107]_ added support for arbitrary annotations on parts
27
+ PEP 3107 [pep-3107]_ added support for arbitrary annotations on parts
26
28
of a function definition. Although no meaning was assigned to
27
29
annotations then, there has always been an implicit goal to use them
28
30
for type hinting, which is listed as the first possible use case in
@@ -311,8 +313,8 @@ Usage Patterns
311
313
312
314
The main use case of type hinting is static analysis using an external
313
315
tool without executing the analyzed program. Existing tools used for
314
- that purpose like ``pyflakes`` [# pyflakes]_ or ``pylint`` [# pylint]_
315
- might be extended to support type checking. New tools, like MyPy 's
316
+ that purpose like ``pyflakes`` [pyflakes]_ or ``pylint`` [pylint]_
317
+ might be extended to support type checking. New tools, like mypy 's
316
318
``mypy -S`` mode, can be adopted specifically for this purpose.
317
319
318
320
Type checking based on type hints is understood as a best-effort
@@ -337,14 +339,14 @@ Existing Approaches in Python
337
339
Cython and Numba
338
340
----------------
339
341
340
- Numba [# numba]_ is a *just-in-time* specializing compiler producing
342
+ Numba [numba]_ is a *just-in-time* specializing compiler producing
341
343
optimized native code from annotated Python and NumPy code.
342
344
343
345
obiwan
344
346
------
345
347
346
- obiwan [# obiwan]_ is a library enabling runtime type checking inspired
347
- by TypeScript [# typescript]_ (see `Existing Approaches in Other
348
+ obiwan [obiwan]_ is a library enabling runtime type checking inspired
349
+ by TypeScript [typescript]_ (see `Existing Approaches in Other
348
350
Languages <#typescript>`_). The syntax leverages function annotations,
349
351
extending it to validate callback functions, elements of dictionaries
350
352
and lists. Type checkers might be functions, in which case a type is
@@ -364,7 +366,7 @@ Examples::
364
366
pytypedecl
365
367
----------
366
368
367
- pytypedecl [# pytypedecl]_ consists of a type declaration language for
369
+ pytypedecl [pytypedecl]_ consists of a type declaration language for
368
370
Python and an optional runtime type checker. Type declarations for
369
371
``module.py`` are kept in a separate file called ``module.pytd``. This
370
372
solves issues with declaration ordering.
@@ -385,7 +387,7 @@ Example::
385
387
Argument Clinic
386
388
---------------
387
389
388
- Argument Clinic [# argumentclinic]_ is a preprocessor for CPython
390
+ Argument Clinic [argumentclinic]_ is a preprocessor for CPython
389
391
C files, automating maintenance of argument parsing code for “builtins”.
390
392
391
393
Example argument declaration::
@@ -418,7 +420,7 @@ Example argument declaration::
418
420
NumPy
419
421
-----
420
422
421
- NumPy [# numpy]_ is an extension to Python adding support for
423
+ NumPy [numpy]_ is an extension to Python adding support for
422
424
multi-dimensional arrays, matrices and operations to operate on those.
423
425
424
426
The project requires typing information in the API documentation. There
@@ -457,7 +459,7 @@ Existing Approaches in Other Languages
457
459
ActionScript
458
460
------------
459
461
460
- ActionScript [# actionscript]_ is a class-based, single inheritance,
462
+ ActionScript [actionscript]_ is a class-based, single inheritance,
461
463
object-oriented superset of ECMAScript. It supports inferfaces and
462
464
strong runtime-checked static typing. Compilation supports a “strict
463
465
dialect” where type mismatches are reported at compile-time.
@@ -489,7 +491,7 @@ Example code with types::
489
491
Dart
490
492
----
491
493
492
- Dart [# dart]_ is a class-based, single inheritance, object-oriented
494
+ Dart [dart]_ is a class-based, single inheritance, object-oriented
493
495
language with C-style syntax. It supports interfaces, abstract classes,
494
496
reified generics, and optional typing.
495
497
@@ -515,7 +517,7 @@ Example code with types::
515
517
Hack
516
518
----
517
519
518
- Hack [# hack]_ is a programming language that interoperates seamlessly
520
+ Hack [hack]_ is a programming language that interoperates seamlessly
519
521
with PHP. It provides opt-in static type checking, type aliasing,
520
522
generics, nullable types, and lambdas.
521
523
@@ -542,7 +544,7 @@ Example code with types::
542
544
TypeScript
543
545
----------
544
546
545
- TypeScript [# typescript]_ is a typed superset of JavaScript that adds
547
+ TypeScript [typescript]_ is a typed superset of JavaScript that adds
546
548
interfaces, classes, mixins and modules to the language.
547
549
548
550
Type checks are duck typed. Multiple valid function signatures are
@@ -623,39 +625,45 @@ the toggle for runtime checks.
623
625
References
624
626
==========
625
627
626
- .. [# pep-3107]
628
+ .. [pep-3107]
627
629
http://www.python.org/dev/peps/pep-3107/
628
630
629
- .. [# mypy]
630
- https ://github.com/JukkaL/ mypy
631
+ .. [mypy]
632
+ http ://mypy-lang.org
631
633
632
- .. [# obiwan]
634
+ .. [obiwan]
633
635
http://pypi.python.org/pypi/obiwan
634
636
635
- .. [# numba]
637
+ .. [numba]
636
638
http://numba.pydata.org
637
639
638
- .. [# pytypedecl]
640
+ .. [pytypedecl]
639
641
https://github.com/google/pytypedecl
640
642
641
- .. [# argumentclinic]
643
+ .. [argumentclinic]
642
644
https://docs.python.org/3/howto/clinic.html
643
645
644
- .. [# numpy]
646
+ .. [numpy]
645
647
http://www.numpy.org
646
648
647
- .. [# typescript]
648
- http://www.typescriptlang.org/
649
+ .. [typescript]
650
+ http://www.typescriptlang.org
649
651
650
- .. [# hack]
651
- http://hacklang.org/
652
+ .. [hack]
653
+ http://hacklang.org
652
654
653
- .. [# dart]
654
- https://www.dartlang.org/
655
+ .. [dart]
656
+ https://www.dartlang.org
655
657
656
- .. [# actionscript]
658
+ .. [actionscript]
657
659
http://livedocs.adobe.com/specs/actionscript/3/
658
660
661
+ .. [pyflakes]
662
+ https://github.com/pyflakes/pyflakes/
663
+
664
+ .. [pylint]
665
+ http://www.pylint.org
666
+
659
667
660
668
Copyright
661
669
=========
0 commit comments