|
1 |
| -# Typing Python 3.5 introducd optional type annotation for functions, and |
2 |
| -that functionality was extended in Python 3.6. |
| 1 | +# Typing |
| 2 | + |
| 3 | +Python 3.5 introducd optional type annotation for functions, and that |
| 4 | +functionality was extended in Python 3.6. |
3 | 5 |
|
4 | 6 | The `mypy` static type checker can use this annotation to detect type errors.
|
5 | 7 |
|
6 | 8 | Type checking can be done using [mypy](http://mypy-lang.org/index.html).
|
7 | 9 |
|
| 10 | + |
8 | 11 | ## What is it?
|
| 12 | + |
9 | 13 | 1. `mypy.ini`: mypy configuration file.
|
10 | 14 | 1. `correct.py`: code that has type annotations, and no type errors.
|
11 |
| -1. `incorrect_01.py`: code that has type annotations, and passes a string to |
12 |
| - a function that expects an `int`. |
| 15 | +1. `incorrect_01.py`: code that has type annotations, and passes a string to a |
| 16 | + function that expects an `int`. |
13 | 17 | 1. `incorrect_02.py`: code that has type annotations, and the result of a
|
14 | 18 | function that returns an `int` is assigned to a `str` variable.
|
15 | 19 | 1. `incorrect_03.py`: code that has type annotations, and the result of a
|
16 |
| - function that returns an `int`, assigns it to a variable that is later |
17 |
| - used as a `str`. |
| 20 | + function that returns an `int`, assigns it to a variable that is later used |
| 21 | + as a `str`. |
18 | 22 | 1. `dict_correct.py`: code that counts the words in a text read from standard
|
19 | 23 | input.
|
20 |
| -1. `dict_incorrect.py`: code that counts the words in a text read from |
21 |
| - standard input. The counts are subsequently normalized to `float`, which |
22 |
| - is a type error. |
23 |
| -1. `people_incorrect.py`: code that defines a `People` class, stores some in |
24 |
| - a list with mistakes. |
| 24 | +1. `dict_incorrect.py`: code that counts the words in a text read from standard |
| 25 | + input. The counts are subsequently normalized to `float`, which is a type |
| 26 | + error. |
| 27 | +1. `people_incorrect.py`: code that defines a `People` class, stores some in a |
| 28 | + list with mistakes. |
25 | 29 | 1. `duck_typing.py`: example code illustrating duck typing.
|
26 |
| -1. `duck_typing_incorrect.py`: example code illustrating duck typing, but |
27 |
| - with an error. |
| 30 | +1. `duck_typing_incorrect.py`: example code illustrating duck typing, but with |
| 31 | + an error. |
28 | 32 | 1. `typed_duck_typing.py`: example code illustrating duck typing using type
|
29 | 33 | hints.
|
30 | 34 | 1. `typed_duck_typing_clean.py`: example code illustrating duck typing using
|
31 | 35 | type hints with a factory function.
|
32 | 36 | 1. `typed_duck_typing_incorrect.py`: example code illustrating duck typing
|
33 | 37 | using type hints with an error.
|
34 |
| -1. `typed_duck_typing_false_positive.py`: example code illustrating duck |
35 |
| - typing using type hints for which mypy 0.910 generates a false positive. |
36 |
| -1. `numpy_typing.py`: illustration of a script using both numpy and |
37 |
| - matplotlib with type hints. |
| 38 | +1. `numpy_typing.py`: illustration of a script using both numpy and matplotlib |
| 39 | + with type hints. |
38 | 40 | 1. `classes.py`: illustration of using type hints with a user-defined class.
|
39 |
| -1. `classes_incorrect.py`: illustration of using type hints with a |
40 |
| - user-defined class with errors. |
| 41 | +1. `classes_incorrect.py`: illustration of using type hints with a user-defined |
| 42 | + class with errors. |
0 commit comments