Skip to content

Commit bfb86d0

Browse files
committed
Remove false positive example
1 parent 57097ca commit bfb86d0

File tree

3 files changed

+22
-60
lines changed

3 files changed

+22
-60
lines changed

source-code/typing/README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
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.
35

46
The `mypy` static type checker can use this annotation to detect type errors.
57

68
Type checking can be done using [mypy](http://mypy-lang.org/index.html).
79

10+
811
## What is it?
12+
913
1. `mypy.ini`: mypy configuration file.
1014
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`.
1317
1. `incorrect_02.py`: code that has type annotations, and the result of a
1418
function that returns an `int` is assigned to a `str` variable.
1519
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`.
1822
1. `dict_correct.py`: code that counts the words in a text read from standard
1923
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.
2529
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.
2832
1. `typed_duck_typing.py`: example code illustrating duck typing using type
2933
hints.
3034
1. `typed_duck_typing_clean.py`: example code illustrating duck typing using
3135
type hints with a factory function.
3236
1. `typed_duck_typing_incorrect.py`: example code illustrating duck typing
3337
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.
3840
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.

source-code/typing/typed_duck_typing.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,5 @@ def sound_repeater(sound_maker: SoundMaker, nr_repeats: int) -> None:
3232
arg_parser.add_argument('--n', type=int, default=1,
3333
help='number of sounds to make')
3434
options = arg_parser.parse_args()
35-
sound_maker: SoundMaker
36-
if options.type == 'duck':
37-
sound_maker = Duck()
38-
else:
39-
sound_maker = AlarmClock()
35+
sound_maker: SoundMaker = Duck() if options.type == 'duck' else AlarmClock()
4036
sound_repeater(sound_maker, options.n)

source-code/typing/typed_duck_typing_false_positive.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)