|
87 | 87 | \end{figure}% |
88 | 88 | % |
89 | 89 | \gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types_wrong.py}{variables:variable_types_wrong:mypy}{% |
90 | | -The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types_wrong}. % |
| 90 | +The results of static type checking with \mypy\ of the program \textil{variable_types_wrong.py} given in \cref{lst:variables:types_wrong}. % |
91 | 91 | (This is actually output generated by the script~\cref{lst:bash:mypy} on \cpageref{lst:bash:mypy}.)}% |
92 | 92 | % |
93 | 93 | \gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types.py}{variables:variable_types:mypy}{% |
94 | | -The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types}. % |
| 94 | +The results of static type checking with \mypy\ of the program \textil{variable_types.py} given in \cref{lst:variables:types}. % |
95 | 95 | (This is actually output generated by the script~\cref{lst:bash:mypy} on \cpageref{lst:bash:mypy}.)}% |
96 | 96 | % |
97 | 97 | A first step to avoiding any type-related errors in programs is, ofcourse, careful programming. |
|
173 | 173 | \cref{lst:variables:types_wrong}, but with the variable explicitly hinted as either \pythonil{int} or \pythonil{float} and named appropriately.}% |
174 | 174 | % |
175 | 175 | \gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types_wrong_hints_1.py}{variables:variable_types_wrong_hints_1:mypy}{% |
176 | | -The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types_wrong_hints_1}.}% |
| 176 | +The results of static type checking the program \textil{variable_types_wrong_hints_1.py} with \mypy\ of the program given in \cref{lst:variables:types_wrong_hints_1}.}% |
177 | 177 | % |
178 | 178 | \gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types_wrong_hints_2.py}{variables:variable_types_wrong_hints_2:mypy}{% |
179 | | -The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types_wrong_hints_2}.}%% |
| 179 | +The results of static type checking the program \textil{variable_types_wrong_hints_2.py} with \mypy\ of the program given in \cref{lst:variables:types_wrong_hints_2}.}%% |
180 | 180 |
|
181 | 181 | If the author of \cref{lst:variables:types_wrong} had used \pglspl{typeHint}, they could have written their program differently, as illustrated in \cref{lst:variables:types_wrong_hints_1,lst:variables:types_wrong_hints_2}. |
182 | 182 | Both programs as well as the original one produce exactly the same output if we execute them with the \python\ interpreter, since \pglspl{typeHint} are ignored by the interpreter. |
|
220 | 220 | A variant of \cref{lst:variables:types} which has been improved by adding type annotations.}% |
221 | 221 | % |
222 | 222 | \gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types_hints.py}{variables:variable_types_hints:mypy}{% |
223 | | -The results of static type checking with \mypy\ of the program \textil{variable_types_hints} given in \cref{lst:variables:types_hints}.} |
| 223 | +The results of static type checking with \mypy\ of the program \textil{variable_types_hints.py} given in \cref{lst:variables:types_hints}.} |
224 | 224 |
|
225 | 225 | For the sake of completeness, let us also annotate \cref{lst:variables:types} with \pglspl{typeHint} as a small exercise. |
226 | 226 | The variable \pythonil{int_var}, in which we want to store the integer value~\pythonil{8}, will be annotated with \pythonil{: int}. |
|
243 | 243 | Therefore, from my perspective, \cref{bp:typeHints} \emph{always} applies. |
244 | 244 |
|
245 | 245 | \gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables assignment_wrong.py}{variables:assignment_wrong:mypy}{% |
246 | | -The results of static type checking with \mypy\ of the program \textil{assignment_wrong} given in \cref{lst:variables:assignment_wrong}.}% |
| 246 | +The results of static type checking the program \textil{assignment_wrong.py} with \mypy\ given in \cref{lst:variables:assignment_wrong}.}% |
247 | 247 | % |
248 | 248 | For the sake of completeness, we also apply \mypy\ to the program \textil{assignment_wrong} given in \cref{lst:variables:assignment_wrong} that we used to illustrate the use of the \pycharm\ \pgls{IDE} in finding bugs. |
249 | 249 | The output given in \cref{exec:variables:assignment_wrong:mypy} informs us about the same error we encountered back in \cref{sec:errorsInIde}: |
|
0 commit comments