pythonkurs2020_1_get_started

Pylint

Über pylint

pylint ist ein hilfreiches Tool, das

Der Coding-Standard nachdem pylint prüft orientiert sich dabei an PEP 8, dem Style Guide für Python Code. Dabei steht “PEP” für “Python Enhancement Proposals”.

Erstes Beispiel

Wir legen eine Datei lec06/ex02_pylint_example.py mit folgendem Inhalt an.

def quicksort(arr):
    print('Ich werde gerade aufgerufen.')
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    Left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    if False:
        print("Tritt niemals ein")
    return quicksort(Left) + middle + quicksort(right)

Jetzt führen wir im Terminal folgenden Befehl aus und erhalten als Output

(.venv)> pylint lec06/ex02_pylint_example.py
************* Module ex02_pylint_example
lec06/ex02_pylint_example.py:1:0: C0114: Missing module docstring (missing-module-docstring)
lec06/ex02_pylint_example.py:1:0: C0116: Missing function or method docstring (missing-function-docstring)
lec06/ex02_pylint_example.py:6:4: C0103: Variable name "Left" doesn't conform to snake_case naming style (invalid-name)
lec06/ex02_pylint_example.py:9:4: W0125: Using a conditional statement with a constant value (using-constant-test)

-------------------------------------------------------------------
Your code has been rated at 6.36/10 (previous run: 10.00/10, -3.64)

Wenn wir uns jetzt dafür interessieren, was mit der Fehlermeldung genau gemeint ist, können wir ausführen

(.venv)> pylint --help-msg=missing-module-docstring
:missing-module-docstring (C0114): *Missing module docstring*
Used when a module has no docstring.Empty modules do not require a docstring.
This message belongs to the basic checker.