|
441 | 441 | We can apply it a file \textil{fileToScan.py} by typing \bashil{pylint fileToScan.py} in a \pgls{terminal}~(\textil{fileToScan.py} can also be a directory). |
442 | 442 | Like with \ruff, in the context of this book, we will disable some \pgls{linter} rules for \pylint, too. |
443 | 443 | This can be done by adding the parameter \textil{--disable=...} with the rules to be deactivated. |
444 | | -The list of rules that \pylint\ applies when analyzing a file can be found at~\cite{PC2024PL}. |
445 | | - |
| 444 | +The list of rules that \pylint\ applies when analyzing a file can be found at~\cite{PC2024PL}.% |
| 445 | +% |
| 446 | +\begin{sloppypar}% |
446 | 447 | Let us now apply both our new \pgls{linter} \pylint\ as well as \ruff, which we ave already used, to the two ideas for enumerating over the data and indices of collections. |
447 | 448 | We first analyze \programUrl{loops:for_loop_no_enumerate_1}, the program where we let the index variable iterate and use it to access the data elements. |
448 | 449 | In \cref{exec:loops:for_loop_no_enumerate_1:pylint}, \pylint\ suggest that we should iterate over the list \pythonil{data} using the \pythonilIdx{enumerate} function, whereas \ruff, at the time of this writing, has no issue with this approach~(see \cref{exec:loops:for_loop_no_enumerate_1:ruff}). |
449 | 450 | Now we analyze \programUrl{loops:for_loop_no_enumerate_2}, where we iterate over the elements of the container and manually maintain an index variable~\pythonil{i}. |
450 | 451 | Interestingly, this time \ruff\ suggests us to~\inQuotes{Use \inSQuotes{\pythonil{enumerate()}} for index variable \inSQuotes{\pythonil{i}} in \inSQuotes{\pythonil{for}} loop}, as shown in \cref{exec:loops:for_loop_no_enumerate_2:ruff}. |
451 | | -\pylint, on the other hand, does not discover any problem with \programUrl{loops:for_loop_no_enumerate_2}. |
452 | | - |
| 452 | +\pylint, on the other hand, does not discover any problem with \programUrl{loops:for_loop_no_enumerate_2}.% |
| 453 | +\end{sloppypar}% |
| 454 | +% |
453 | 455 | Our two \pglspl{linter} have discovered the same issue, just with different programs. |
454 | 456 | They independently propose using a function called \pythonilIdx{enumerate} to solve the problem of iterating over collections and knowing the index of the current element. |
455 | 457 | But what is \pythonilIdx{enumerate}? |
|
0 commit comments