Pylint
Message types
  • (C) convention, for programming standard violation
  • (R) refactor, for bad code smell
  • (W) warning, for python specific problems
  • (E) error, for much probably bugs in the code
  • (F) fatal, if an error occurred which prevented pylint from doing
  • Original code
    #!/usr/bin/python
    
    '''Convert a file to a all upper case file.
    
    '''
    
    __author__ = "Lin Chen"
    __version__ = "0.1"
    
    from m1 import convertRead, convertWrite;
    from m2 import upper;
    import sys;
    
    def main():
        '''Convert all characters in a file to upper case and save it.
    
        Raises:
            IOError: input file cannot be openned, or output file cannot be created.
    
        '''
        if len(sys.argv) != 3:
            print 'python convert.py [inputFile] [outputFile]';
            exit();
    
        l = convertRead(sys.argv[1]); # read file
        l = upper(l); # convert strings to upper case
        convertWrite(l, sys.argv[2]); # save to output file
    
    if __name__ == '__main__':
        main();
    		
    pylint convert.py --reports=y
    ************* Module convert
    W: 10, 0: Unnecessary semicolon (unnecessary-semicolon)
    W: 11, 0: Unnecessary semicolon (unnecessary-semicolon)
    W: 12, 0: Unnecessary semicolon (unnecessary-semicolon)
    W: 22, 0: Unnecessary semicolon (unnecessary-semicolon)
    W: 23, 0: Unnecessary semicolon (unnecessary-semicolon)
    W: 25, 0: Unnecessary semicolon (unnecessary-semicolon)
    W: 26, 0: Unnecessary semicolon (unnecessary-semicolon)
    W: 27, 0: Unnecessary semicolon (unnecessary-semicolon)
    W: 30, 0: Unnecessary semicolon (unnecessary-semicolon)
    C: 25, 4: Variable name "l" doesn't conform to snake_case naming style (invalid-name)
    C: 26, 4: Variable name "l" doesn't conform to snake_case naming style (invalid-name)
    C: 12, 0: standard import "import sys" should be placed before "from m1 import convertRead, convertWrite" (wrong-import-order)
    
    
    Report
    ======
    14 statements analysed.
    
    Statistics by type
    ------------------
    
    +---------+-------+-----------+-----------+------------+---------+
    |type     |number |old number |difference |%documented |%badname |
    +=========+=======+===========+===========+============+=========+
    |module   |1      |1          |=          |100.00      |0.00     |
    +---------+-------+-----------+-----------+------------+---------+
    |class    |0      |0          |=          |0           |0        |
    +---------+-------+-----------+-----------+------------+---------+
    |method   |0      |0          |=          |0           |0        |
    +---------+-------+-----------+-----------+------------+---------+
    |function |1      |1          |=          |100.00      |0.00     |
    +---------+-------+-----------+-----------+------------+---------+
    
    
    
    External dependencies
    ---------------------
    ::
    
        m1 (convert)
        m2 (convert)
    
    
    
    Raw metrics
    -----------
    
    +----------+-------+------+---------+-----------+
    |type      |number |%     |previous |difference |
    +==========+=======+======+=========+===========+
    |code      |15     |48.39 |15       |=          |
    +----------+-------+------+---------+-----------+
    |docstring |9      |29.03 |9        |=          |
    +----------+-------+------+---------+-----------+
    |comment   |1      |3.23  |1        |=          |
    +----------+-------+------+---------+-----------+
    |empty     |6      |19.35 |6        |=          |
    +----------+-------+------+---------+-----------+
    
    
    
    Duplication
    -----------
    
    +-------------------------+------+---------+-----------+
    |                         |now   |previous |difference |
    +=========================+======+=========+===========+
    |nb duplicated lines      |0     |0        |=          |
    +-------------------------+------+---------+-----------+
    |percent duplicated lines |0.000 |0.000    |=          |
    +-------------------------+------+---------+-----------+
    
    
    
    Messages by category
    --------------------
    
    +-----------+-------+---------+-----------+
    |type       |number |previous |difference |
    +===========+=======+=========+===========+
    |convention |3      |3        |=          |
    +-----------+-------+---------+-----------+
    |refactor   |0      |0        |=          |
    +-----------+-------+---------+-----------+
    |warning    |9      |9        |=          |
    +-----------+-------+---------+-----------+
    |error      |0      |0        |=          |
    +-----------+-------+---------+-----------+
    
    
    
    Messages
    --------
    
    +----------------------+------------+
    |message id            |occurrences |
    +======================+============+
    |unnecessary-semicolon |9           |
    +----------------------+------------+
    |invalid-name          |2           |
    +----------------------+------------+
    |wrong-import-order    |1           |
    +----------------------+------------+
    
    
    
    
    ------------------------------------------------------------------
    Your code has been rated at 1.43/10 (previous run: 1.43/10, +0.00)
    
    		
    Revised code
    #!/usr/bin/python
    
    '''Convert a file to a all upper case file.
    
    '''
    
    __author__ = "Lin Chen"
    __version__ = "0.1"
    
    import sys
    from m1 import convertRead, convertWrite
    from m2 import upper
    
    def main():
        '''Convert all characters in a file to upper case and save it.
    
        Raises:
            IOError: input file cannot be openned, or output file cannot be created.
    
        '''
        if len(sys.argv) != 3:
            print 'python convert.py [inputFile] [outputFile]'
            exit()
    
        lines_of_file = convertRead(sys.argv[1])  # read file
        upper_lines = upper(lines_of_file)  # convert strings to upper case
        convertWrite(upper_lines, sys.argv[2])  # save to output file
    
    if __name__ == '__main__':
        main()
    		
    pylint convert.py --reports=y
    Report
    ======
    14 statements analysed.
    
    Statistics by type
    ------------------
    
    +---------+-------+-----------+-----------+------------+---------+
    |type     |number |old number |difference |%documented |%badname |
    +=========+=======+===========+===========+============+=========+
    |module   |1      |1          |=          |100.00      |0.00     |
    +---------+-------+-----------+-----------+------------+---------+
    |class    |0      |0          |=          |0           |0        |
    +---------+-------+-----------+-----------+------------+---------+
    |method   |0      |0          |=          |0           |0        |
    +---------+-------+-----------+-----------+------------+---------+
    |function |1      |1          |=          |100.00      |0.00     |
    +---------+-------+-----------+-----------+------------+---------+
    
    
    
    External dependencies
    ---------------------
    ::
    
        m1 (convert)
        m2 (convert)
    
    
    
    Raw metrics
    -----------
    
    +----------+-------+------+---------+-----------+
    |type      |number |%     |previous |difference |
    +==========+=======+======+=========+===========+
    |code      |15     |48.39 |15       |=          |
    +----------+-------+------+---------+-----------+
    |docstring |9      |29.03 |9        |=          |
    +----------+-------+------+---------+-----------+
    |comment   |1      |3.23  |1        |=          |
    +----------+-------+------+---------+-----------+
    |empty     |6      |19.35 |6        |=          |
    +----------+-------+------+---------+-----------+
    
    
    
    Duplication
    -----------
    
    +-------------------------+------+---------+-----------+
    |                         |now   |previous |difference |
    +=========================+======+=========+===========+
    |nb duplicated lines      |0     |0        |=          |
    +-------------------------+------+---------+-----------+
    |percent duplicated lines |0.000 |0.000    |=          |
    +-------------------------+------+---------+-----------+
    
    
    
    Messages by category
    --------------------
    
    +-----------+-------+---------+-----------+
    |type       |number |previous |difference |
    +===========+=======+=========+===========+
    |convention |0      |0        |=          |
    +-----------+-------+---------+-----------+
    |refactor   |0      |0        |=          |
    +-----------+-------+---------+-----------+
    |warning    |0      |2        |-2.00      |
    +-----------+-------+---------+-----------+
    |error      |0      |2        |-2.00      |
    +-----------+-------+---------+-----------+
    
    
    
    
    -------------------------------------------------------------------
    Your code has been rated at 10.00/10 (previous run: 1.43/10, +8.57)
    
    		
    Reference
  • Pylint tutorial
  • Pylint