Suggest adding to Articles
reorx opened this issue · comments
Below is a personal document I wrote before, might be useful for people who are new to python typing, feel free to take some into the Articles part.
Python Type Hints
Basic Guides
- PEP 483 -- The Theory of Type Hints: https://www.python.org/dev/peps/pep-0483/
- PEP 484 -- Type Hints: https://www.python.org/dev/peps/pep-0484/
- PEP 3107 -- Function Annotations: https://www.python.org/dev/peps/pep-3107/
- PEP 526 -- Syntax for Variable Annotations: https://www.python.org/dev/peps/pep-0526/
- mypy
- PyCharm: https://www.jetbrains.com/help/pycharm/type-hinting-in-product.html
Advanced Guides
PEP 563 -- Postponed Evaluation of Annotations
https://www.python.org/dev/peps/pep-0563/
This PEP describes the support of referencing a type that is yet to defined in the annotation, and how to enabling it by calling from __future__ import annotations
in Python after 3.7
In Python before 3.7 (<= 3.6), same thing can be achieved by adding single quote around the type, this is called Forward references in PEP 484.
Literal
- mypy Literal: https://mypy.readthedocs.io/en/latest/literal_types.html
- PEP 586 -- Literal Types: https://www.python.org/dev/peps/pep-0586/
Protocol
- mypy Protocol: https://mypy.readthedocs.io/en/latest/protocols.html
- PEP 544 -- Protocols: Structural subtyping (static duck typing): https://www.python.org/dev/peps/pep-0544/
Generic
- mypy Generics: https://mypy.readthedocs.io/en/latest/generics.html
- PEP 483 Defining and using generic types: https://www.python.org/dev/peps/pep-0483/#defining-and-using-generic-types
- PEP 484 User-defined generic types: https://www.python.org/dev/peps/pep-0484/#user-defined-generic-types
@reorx PEPs are 100% should be listed in this doc. Thanks! Can you please add them?