|
2 | 2 | \label{sec:variableTypesAndTypeHints}%
|
3 | 3 | %
|
4 | 4 | \hsection{Variable Types}%
|
5 |
| -\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{variable_types.py}{--args format}{variables:types}{% |
| 5 | +\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{variable_types.py}{--args format}{variables:types}{% |
6 | 6 | An example of the types of variables.}%
|
7 | 7 | %
|
8 | 8 | A variable is basically a name pointing to an object.
|
|
15 | 15 | %
|
16 | 16 | \hsection{Types and Confusion}%
|
17 | 17 | \label{sec:typesAndConfusion}%
|
18 |
| -\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{variable_types_wrong.py}{--args format}{variables:types_wrong}{% |
| 18 | +\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{variable_types_wrong.py}{--args format}{variables:types_wrong}{% |
19 | 19 | An example of the confusing variable types.}
|
20 | 20 |
|
21 | 21 | Well, actually, there is.
|
|
86 | 86 | \label{fig:pipInstallMypy}%
|
87 | 87 | \end{figure}%
|
88 | 88 | %
|
89 |
| -\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/mypy.sh 01_variables variable_types_wrong.py}{variables:variable_types_wrong:mypy}{% |
| 89 | +\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types_wrong.py}{variables:variable_types_wrong:mypy}{% |
90 | 90 | The results of static type checking with \mypy\ of the program 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 |
| -\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/mypy.sh 01_variables variable_types.py}{variables:variable_types:mypy}{% |
| 93 | +\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types.py}{variables:variable_types:mypy}{% |
94 | 94 | The results of static type checking with \mypy\ of the program 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 | %
|
|
166 | 166 | However, by writing \pythonil{: int}\pythonIdx{:} after its name, we also clearly establish our intention.
|
167 | 167 | And this makes a difference.
|
168 | 168 |
|
169 |
| -\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{variable_types_wrong_hints_1.py}{--args format}{variables:types_wrong_hints_1}{% |
| 169 | +\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{variable_types_wrong_hints_1.py}{--args format}{variables:types_wrong_hints_1}{% |
170 | 170 | \cref{lst:variables:types_wrong}, but with the variable explicitly hinted as \pythonil{int}.}%
|
171 | 171 | %%
|
172 |
| -\gitPythonAndOutput{\programmingWithPythonCodeRepo}{01_variables}{variable_types_wrong_hints_2.py}{--args format}{variables:types_wrong_hints_2}{% |
| 172 | +\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{variable_types_wrong_hints_2.py}{--args format}{variables:types_wrong_hints_2}{% |
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 |
| -\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/mypy.sh 01_variables variable_types_wrong_hints_1.py}{variables:variable_types_wrong_hints_1:mypy}{% |
| 175 | +\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types_wrong_hints_1.py}{variables:variable_types_wrong_hints_1:mypy}{% |
176 | 176 | The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types_wrong_hints_1}.}%
|
177 | 177 | %
|
178 |
| -\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/mypy.sh 01_variables variable_types_wrong_hints_2.py}{variables:variable_types_wrong_hints_2:mypy}{% |
| 178 | +\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types_wrong_hints_2.py}{variables:variable_types_wrong_hints_2:mypy}{% |
179 | 179 | The results of static type checking 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}.
|
|
205 | 205 | %
|
206 | 206 | \bestPractice{typeHints}{Always use \pglspl{typeHint}.}%
|
207 | 207 | %
|
208 |
| -\gitPython{\programmingWithPythonCodeRepo}{01_variables/variable_types_hints.py}{--args format}{variables:types_hints}{% |
| 208 | +\gitPython{\programmingWithPythonCodeRepo}{variables/variable_types_hints.py}{--args format}{variables:types_hints}{% |
209 | 209 | A variant of \cref{lst:variables:types} which has been improved by adding type annotations.}%
|
210 | 210 | %
|
211 |
| -\gitOutputTool{\programmingWithPythonCodeRepo}{.}{scripts/mypy.sh 01_variables variable_types_hints.py}{variables:variable_types_hints:mypy}{% |
| 211 | +\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh variables variable_types_hints.py}{variables:variable_types_hints:mypy}{% |
212 | 212 | The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types_hints}.}
|
213 | 213 |
|
214 | 214 | For the sake of completeness, let us also annotate \cref{lst:variables:types} with \pglspl{typeHint} as a small exercise.
|
|
0 commit comments