You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guide/src/python-typing-hints.md
+77-1Lines changed: 77 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ As we can see, those are not full definitions containing implementation, but jus
41
41
42
42
### What do the PEPs say?
43
43
44
-
At the time of writing this documentation, the `pyi` files are referenced in three PEPs.
44
+
At the time of writing this documentation, the `pyi` files are referenced in four PEPs.
45
45
46
46
[PEP8 - Style Guide for Python Code - #Function Annotations](https://www.python.org/dev/peps/pep-0008/#function-annotations) (last point) recommends all third party library creators to provide stub files as the source of knowledge about the package for type checker tools.
47
47
@@ -55,6 +55,8 @@ It contains a specification for them (highly recommended reading, since it conta
55
55
56
56
[PEP561 - Distributing and Packaging Type Information](https://www.python.org/dev/peps/pep-0561/) describes in detail how to build packages that will enable type checking. In particular it contains information about how the stub files must be distributed in order for type checkers to use them.
57
57
58
+
[PEP560 - Core support for typing module and generic types](https://www.python.org/dev/peps/pep-0560/) describes the details on how Python's type system internally supports generics, including both runtime behavior and integration with static type checkers.
59
+
58
60
## How to do it?
59
61
60
62
[PEP561](https://www.python.org/dev/peps/pep-0561/) recognizes three ways of distributing type information:
@@ -165,3 +167,77 @@ class Car:
165
167
:return: the name of the color our great algorithm thinks is the best for this car
166
168
"""
167
169
```
170
+
171
+
### Supporting Generics
172
+
173
+
Type annotations can also be made generic in Python. They are useful for working
174
+
with different types while maintaining type safety. Usually, generic classes
175
+
inherit from the `typing.Generic` metaclass.
176
+
177
+
Take for example the following `.pyi` file that specifies a `Car` that can
0 commit comments