Pylint Documentation Release 2.7.3

Total Page:16

File Type:pdf, Size:1020Kb

Pylint Documentation Release 2.7.3 Pylint Documentation Release 2.7.3 Logilab, PyCQA and contributors Mar 29, 2021 Contents 1 Introduction 3 1.1 What is Pylint?..............................................3 1.2 What Pylint is not?............................................3 2 Tutorial 5 2.1 Intro...................................................5 2.2 Getting Started..............................................5 2.3 Your First Pylint’ing...........................................6 2.4 The Next Step..............................................8 3 User Guide 11 3.1 Installation................................................ 11 3.2 Running Pylint.............................................. 11 3.3 Pylint output............................................... 14 3.4 Messages control............................................. 16 3.5 Configuration............................................... 19 3.6 Editor and IDE integration........................................ 21 4 How To Guides 27 4.1 How to Write a Checker......................................... 27 4.2 How To Write a Pylint Plugin...................................... 31 4.3 Transform plugins............................................ 32 5 Technical Reference 35 5.1 Startup and the Linter Class....................................... 35 5.2 Checkers................................................. 35 5.3 Optional Pylint checkers in the extensions module........................... 35 5.4 Pylint features.............................................. 43 5.5 Pylint and C extensions......................................... 74 6 Development 75 6.1 Contributing............................................... 75 7 Frequently Asked Questions 79 7.1 1. About Pylint.............................................. 79 7.2 2. Installation............................................... 79 7.3 3. Running Pylint............................................. 80 i 7.4 4. Message Control............................................ 81 7.5 5. Classes and Inheritance........................................ 82 7.6 6. Troubleshooting............................................ 82 8 Some projects using Pylint 85 9 Support 87 10 What’s New in Pylint 89 10.1 What’s New in Pylint 2.8......................................... 89 10.2 What’s New in Pylint 2.7......................................... 89 10.3 What’s New in Pylint 2.6......................................... 91 10.4 What’s New in Pylint 2.5......................................... 91 10.5 What’s New in Pylint 2.4......................................... 93 10.6 What’s New in Pylint 2.3......................................... 96 10.7 What’s New in Pylint 2.2......................................... 97 10.8 What’s New in Pylint 2.1......................................... 98 10.9 What’s New in Pylint 2.0......................................... 99 10.10 What’s New In Pylint 1.9........................................ 104 10.11 What’s New In Pylint 1.8........................................ 106 10.12 What’s New In Pylint 1.7........................................ 111 10.13 What’s New In Pylint 1.6........................................ 124 10.14 Pylint’s ChangeLog........................................... 127 Index 197 ii Pylint Documentation, Release 2.7.3 Pylint is a tool that checks for errors in Python code, tries to enforce a coding standard and looks for code smells. It can also look for certain type errors, it can recommend suggestions about how particular blocks can be refactored and can offer you details about the code’s complexity. Contents 1 Pylint Documentation, Release 2.7.3 2 Contents CHAPTER 1 Introduction 1.1 What is Pylint? Pylint is a tool that checks for errors in Python code, tries to enforce a coding standard and looks for code smells. It can also look for certain type errors, it can recommend suggestions about how particular blocks can be refactored and can offer you details about the code’s complexity. Other similar projects would include pychecker (now defunct), pyflakes, flake8, and mypy. The default coding style used by Pylint is close to PEP 8. Pylint will display a number of messages as it analyzes the code and it can also be used for displaying some statistics about the number of warnings and errors found in different files. The messages are classified under various categories such as errors and warnings. Last but not least, the code is given an overall mark, based on the number and severity of the warnings and errors. 1.2 What Pylint is not? What Pylint says is not to be taken as gospel and Pylint isn’t smarter than you are: it may warn you about things that you have conscientiously done. Pylint tries hard to report as few false positives as possible for errors, but it may be too verbose with warnings. That’s for example because it tries to detect things that may be dangerous in a context, but are not in others, or because it checks for some things that you don’t care about. Generally, you shouldn’t expect Pylint to be totally quiet about your code, so don’t necessarily be alarmed if it gives you a hell lot of messages for your project! The best way to tackle pylint’s verboseness is to: • enable or disable the messages or message categories that you want to be activated or not for when pylint is analyzing your code. This can be done easily through a command line flag. For instance, disabling all convention messages is simple as a --disable=C option added to pylint command. • create a custom configuration file, tailored to your needs. You can generate one using pylint’s command --generate-rcfile. 3 Pylint Documentation, Release 2.7.3 4 Chapter 1. Introduction CHAPTER 2 Tutorial Author Robert Kirkpatrick 2.1 Intro Beginner to coding standards? Pylint can be your guide to reveal what’s really going on behind the scenes and help you to become a more aware programmer. Sharing code is a rewarding endeavor. Putting your code out there can be either an act of philanthropy, coming of age, or a basic extension of belief in open source. Whatever the motivation, your good intentions may not have the desired outcome if people find your code hard to use or understand. The Python community has formalized some recommended programming styles to help everyone write code in a common, agreed-upon style that makes the most sense for shared code. This style is captured in PEP 8, the "Style Guide for Python Code". Pylint can be a quick and easy way of seeing if your code has captured the essence of PEP 8 and is therefore friendly to other potential users. Perhaps you’re not ready to share your code but you’d like to learn a bit more about writing better code and don’t know where to start. Pylint can tell you where you may have run astray and point you in the direction to figure out what you have done and how to do better. This tutorial is all about approaching coding standards with little or no knowledge of in-depth programming or the code standards themselves. It’s the equivalent of skipping the manual and jumping right in. My command line prompt for these examples is: robertk01 Desktop$ 2.2 Getting Started Running Pylint with no arguments will invoke the help dialogue and give you an idea of the arguments available to you. Do that now, i.e.: 5 Pylint Documentation, Release 2.7.3 robertk01 Desktop$ pylint ... a bunch of stuff ... A couple of the options that we’ll focus on here are: Commands: --help-msg=<msg-id> --generate-rcfile Messages control: --disable=<msg-ids> Reports: --reports=<y_or_n> --output-format=<format> If you need more detail, you can also ask for an even longer help message, like so: robertk01 Desktop$ pylint --long-help ... Even more stuff ... Pay attention to the last bit of this longer help output. This gives you a hint of what Pylint is going to pick on: Output: Using the default text output, the message format is : MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE There are5 kind of message types : * (C) convention, for programming standard violation * (R) refactor, for bad code smell * (W) warning, for python specific problems * (E) error, for probable bugs in the code * (F) fatal, if an error occurred which prevented pylint from doing further processing. When Pylint is first run on a fresh piece of code, a common complaint is that it is too noisy. The current default configuration is set to enforce all possible warnings. We’ll use some of the options I noted above to make it suit your preferences a bit better (and thus make it emit messages only when needed). 2.3 Your First Pylint’ing We’ll use a basic Python script as fodder for our tutorial. The starting code we will use is called simplecaesar.py and is here in its entirety: 1 #!/usr/bin/env python3 2 3 import string; 4 5 shift=3 6 choice= input("would you like to encode or decode?") 7 word= input("Please enter text") 8 letters= string.ascii_letters+ string.punctuation+ string.digits 9 encoded='' 10 if choice =="encode": (continues on next page) 6 Chapter 2. Tutorial Pylint Documentation, Release 2.7.3 (continued from previous page) 11 for letter in word: 12 if letter =='': 13 encoded= encoded+'' 14 else: 15x= letters.index(letter)+ shift 16 encoded= encoded+ letters[x] 17 if choice =="decode": 18 for letter in word: 19 if letter =='': 20 encoded= encoded+'' 21 else: 22x= letters.index(letter)- shift 23 encoded= encoded+ letters[x] 24 25 print(encoded) Let’s get started. If we run this: robertk01 Desktop$ pylint simplecaesar.py ************* Module simplecaesar simplecaesar.py:3:0: W0301: Unnecessary semicolon (unnecessary-semicolon) simplecaesar.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Recommended publications
  • UNIX and Computer Science Spreading UNIX Around the World: by Ronda Hauben an Interview with John Lions
    Winter/Spring 1994 Celebrating 25 Years of UNIX Volume 6 No 1 "I believe all significant software movements start at the grassroots level. UNIX, after all, was not developed by the President of AT&T." Kouichi Kishida, UNIX Review, Feb., 1987 UNIX and Computer Science Spreading UNIX Around the World: by Ronda Hauben An Interview with John Lions [Editor's Note: This year, 1994, is the 25th anniversary of the [Editor's Note: Looking through some magazines in a local invention of UNIX in 1969 at Bell Labs. The following is university library, I came upon back issues of UNIX Review from a "Work In Progress" introduced at the USENIX from the mid 1980's. In these issues were articles by or inter- Summer 1993 Conference in Cincinnati, Ohio. This article is views with several of the pioneers who developed UNIX. As intended as a contribution to a discussion about the sig- part of my research for a paper about the history and devel- nificance of the UNIX breakthrough and the lessons to be opment of the early days of UNIX, I felt it would be helpful learned from it for making the next step forward.] to be able to ask some of these pioneers additional questions The Multics collaboration (1964-1968) had been created to based on the events and developments described in the UNIX "show that general-purpose, multiuser, timesharing systems Review Interviews. were viable." Based on the results of research gained at MIT Following is an interview conducted via E-mail with John using the MIT Compatible Time-Sharing System (CTSS), Lions, who wrote A Commentary on the UNIX Operating AT&T and GE agreed to work with MIT to build a "new System describing Version 6 UNIX to accompany the "UNIX hardware, a new operating system, a new file system, and a Operating System Source Code Level 6" for the students in new user interface." Though the project proceeded slowly his operating systems class at the University of New South and it took years to develop Multics, Doug Comer, a Profes- Wales in Australia.
    [Show full text]
  • Introduction to Eclipse and Pydev Fall 2021 Page 1 of 6
    Introduction to Eclipse and PyDev Fall 2021 Page 1 of 6 Introduction to Eclipse and PyDev We will be using Eclipse PyDev plugin in this course to create and run Python programs. Eclipse is a platform that can be used for application development tasks using different languages, including Java and Python. A separate handout describes how to install Eclipse and its Python plugin - PyDev. This handout will take you through the process of creating and running a Python program. Specifying the Eclipse workspace When you start Eclipse, you will be asked to specify the directory in which to store your projects. By default, on Windows, it creates a folder called eclipse-workspace in your personal folder Use this directory or another of your choice. To switch the workspace to a different folder, after starting Eclipse, go to File > Switch Workspace and select the desired folder. Creating a new PyDev project To create and run a Python program in Eclipse, you must form a project for it: 1. Create a new PyDev Project by selecting File > New > Project>PyDev > PyDev Project. This will open the PyDev Project dialog window (see Error! Reference source not found.) 2. In the dialog window: • Enter a project name of your choice into the Project name field. 3. In the PyDev Project dialog box ( Figure 1), make sure the right interpreter is selected (To make sure python version 3 is selected, click on Configure the interpreter not listed link verifying that the selected interpreter’s location should be within anaconda3 installation, i.e. mention anaconda3 in the path (Figure 2) ) Click on Finish.
    [Show full text]
  • To Type Or Not to Type: Quantifying Detectable Bugs in Javascript
    To Type or Not to Type: Quantifying Detectable Bugs in JavaScript Zheng Gao Christian Bird Earl T. Barr University College London Microsoft Research University College London London, UK Redmond, USA London, UK [email protected] [email protected] [email protected] Abstract—JavaScript is growing explosively and is now used in to invest in static type systems for JavaScript: first Google large mature projects even outside the web domain. JavaScript is released Closure1, then Microsoft published TypeScript2, and also a dynamically typed language for which static type systems, most recently Facebook announced Flow3. What impact do notably Facebook’s Flow and Microsoft’s TypeScript, have been written. What benefits do these static type systems provide? these static type systems have on code quality? More concretely, Leveraging JavaScript project histories, we select a fixed bug how many bugs could they have reported to developers? and check out the code just prior to the fix. We manually add The fact that long-running JavaScript projects have extensive type annotations to the buggy code and test whether Flow and version histories, coupled with the existence of static type TypeScript report an error on the buggy code, thereby possibly systems that support gradual typing and can be applied to prompting a developer to fix the bug before its public release. We then report the proportion of bugs on which these type systems JavaScript programs with few modifications, enables us to reported an error. under-approximately quantify the beneficial impact of static Evaluating static type systems against public bugs, which type systems on code quality.
    [Show full text]
  • Python for Bioinformatics, Second Edition
    PYTHON FOR BIOINFORMATICS SECOND EDITION CHAPMAN & HALL/CRC Mathematical and Computational Biology Series Aims and scope: This series aims to capture new developments and summarize what is known over the entire spectrum of mathematical and computational biology and medicine. It seeks to encourage the integration of mathematical, statistical, and computational methods into biology by publishing a broad range of textbooks, reference works, and handbooks. The titles included in the series are meant to appeal to students, researchers, and professionals in the mathematical, statistical and computational sciences, fundamental biology and bioengineering, as well as interdisciplinary researchers involved in the field. The inclusion of concrete examples and applications, and programming techniques and examples, is highly encouraged. Series Editors N. F. Britton Department of Mathematical Sciences University of Bath Xihong Lin Department of Biostatistics Harvard University Nicola Mulder University of Cape Town South Africa Maria Victoria Schneider European Bioinformatics Institute Mona Singh Department of Computer Science Princeton University Anna Tramontano Department of Physics University of Rome La Sapienza Proposals for the series should be submitted to one of the series editors above or directly to: CRC Press, Taylor & Francis Group 3 Park Square, Milton Park Abingdon, Oxfordshire OX14 4RN UK Published Titles An Introduction to Systems Biology: Statistical Methods for QTL Mapping Design Principles of Biological Circuits Zehua Chen Uri Alon
    [Show full text]
  • Safejava: a Unified Type System for Safe Programming
    SafeJava: A Unified Type System for Safe Programming by Chandrasekhar Boyapati B.Tech. Indian Institute of Technology, Madras (1996) S.M. Massachusetts Institute of Technology (1998) Submitted to the Department of Electrical Engineering and Computer Science in partial fulfillment of the requirements for the degree of Doctor of Philosophy at the MASSACHUSETTS INSTITUTE OF TECHNOLOGY February 2004 °c Massachusetts Institute of Technology 2004. All rights reserved. Author............................................................................ Chandrasekhar Boyapati Department of Electrical Engineering and Computer Science February 2, 2004 Certified by........................................................................ Martin C. Rinard Associate Professor, Electrical Engineering and Computer Science Thesis Supervisor Accepted by....................................................................... Arthur C. Smith Chairman, Department Committee on Graduate Students SafeJava: A Unified Type System for Safe Programming by Chandrasekhar Boyapati Submitted to the Department of Electrical Engineering and Computer Science on February 2, 2004, in partial fulfillment of the requirements for the degree of Doctor of Philosophy Abstract Making software reliable is one of the most important technological challenges facing our society today. This thesis presents a new type system that addresses this problem by statically preventing several important classes of programming errors. If a program type checks, we guarantee at compile time that the program
    [Show full text]
  • Introduction to Python for IBM I
    Introduction to Python for IBM i Mike Pavlak – IT Strategist [email protected] Agenda ■ A little about Python ■ Why use Python ■ How to install/determine if installed ▶IDE ■ Syntax 101 ▶Variables ▶Strings ▶Functions 2 Acknowledgements ■ Kevin Adler ■ Tony Cairns ■ Jesse Gorzinski ■ Google ■ Memegenerator ■ Corn chips and salsa ■ Parrots ■ And, of course, spam 3 A little about Python What is it, really? ■ General purpose language ■ Easy to get started ■ Simple syntax ■ Great for integrations (glue between systems) ■ Access to C and other APIs ■ Infrastructure first, but applications, too 5 Historically… ■ Python was conceptualized by Guido Van Rossum in the late 1980’s ■ Rossum published the first version of Python code (0.9.0) in February of 1991 at the CWI(Centrum Wiskunde & Informatica) in the Netherlands, Amsterdam ■ Python is derived from the ABC programming language, which is a general purpose language that was also developed at CWI. ■ Rossum chose the name “Python” since he was a fan of Monty Python’s Flying Circus. ■ Python is now maintained by a core development team at the institute, although Rossum still holds a vital role in directing its progress and as leading “commitor”. 6 Python lineage ■ Python 1 – 1994 ■ Python 2 – 2000 (Not dead yet…) ▶2.7 – 2010 ■ Python 3 – 2008 ▶3.5 – 2015 ▶3.6.2 – July 2017 ▶3.7 ➔ ETA July 2018 7 Python 2 or 3? 8 What’s the diff? ■ Example: ▶Python 2 print statement replaced by function ● Python 2 – print “Hello World!” ● Python 3 – print(“Hello World!”) ■ Many more differences, tho…
    [Show full text]
  • Lint, a C Program Checker Lint, a C
    Lint, a C Program Checker Fr ans Kunst Vrije Universiteit Amsterdam Afstudeer verslag 18 mei 1988 Lint, a C Program Checker Fr ans Kunst Vrije Universiteit Amsterdam This document describes an implementation of a program which does an extensive consistencyand plausibility check on a set of C program files. This may lead to warnings which help the programmer to debug the program, to remove useless code and to improve his style. The program has been used to test itself and has found bugs in sources of some heavily used code. -2- Contents 1. Introduction 2. Outline of the program 3. What lint checks 3.1 Set, used and unused variables 3.2 Flowofcontrol 3.3 Functions 3.4 Undefined evaluation order 3.5 Pointer alignment problems 3.6 Libraries 4. Howlint checks 4.1 The first pass data structure 4.2 The first pass checking mechanism 4.3 The second pass data structure 4.4 The second pass checking mechanism 5. Howtomakelint shut up 6. User options 7. Ideas for further development 8. Testing the program 9. References Appendix A − The warnings Appendix B − The Ten Commandments for C programmers -3- 1. Introduction C[1][2] is a dangerous programming language. The programmer is allowed to do almost anything, as long as the syntax of the program is correct. This has a reason. In this way it is possible to makeafast compiler which produces fast code. The compiler will be fast because it doesn’tdomuch checking at com- pile time. The code is fast because the compiler doesn’tgenerate run time checks.
    [Show full text]
  • Python-101.Pdf
    What is Python? I Object-oriented, rapid prototyping language I Multi-purpose: Web, GUI, scripting, science, etc. I Interpreted and interactive; very easy to learn I Strongly typed and dynamically typed I Focus on readability and productivity I Extensive standard library and community I CPython, Jython, IronPython, PyPy, etc. I Home page: http://www.python.org/ Python 101 1 Who uses Python? I Google (various projects) I NASA (several projects) I NYSE (one of only three languages \on the floor") I Industrial Light & Magic (everything) I Yahoo! (Yahoo mail & groups) I RealNetworks (function and load testing) I RedHat and Ubuntu (Linux installation tools) I LLNL, Fermilab (steering scientific applications) More success stories at http://www.pythonology.com/ Python 101 2 Python vs Java Python Java I Dynamically typed I Statically typed (assign names to values) (must declare variables) I Concise: \expressing much I Verbose: \abounding in in a few words; implies words; using or containing clean-cut brevity, attained by more words than are excision of the superfluous” necessary" import java.io.*; ... # open the filed.txt // open the filed.txt myFile = open("d.txt") BufferedReader myFile = new BufferedReader( new FileReader("d.txt")); http://pythonconquerstheuniverse.wordpress.com/category/java-and-python/ Python 101 3 Some Basics I Indentation matters (no braces!) I Type matters (must be consistent) I Comments start with a # I Strings use 's or "s (or """s) I print (vs System.out.println) I None ≈ null, self ≈ this I and, or, not instead of &&,
    [Show full text]
  • Sage Tutorial (Pdf)
    Sage Tutorial Release 9.4 The Sage Development Team Aug 24, 2021 CONTENTS 1 Introduction 3 1.1 Installation................................................4 1.2 Ways to Use Sage.............................................4 1.3 Longterm Goals for Sage.........................................5 2 A Guided Tour 7 2.1 Assignment, Equality, and Arithmetic..................................7 2.2 Getting Help...............................................9 2.3 Functions, Indentation, and Counting.................................. 10 2.4 Basic Algebra and Calculus....................................... 14 2.5 Plotting.................................................. 20 2.6 Some Common Issues with Functions.................................. 23 2.7 Basic Rings................................................ 26 2.8 Linear Algebra.............................................. 28 2.9 Polynomials............................................... 32 2.10 Parents, Conversion and Coercion.................................... 36 2.11 Finite Groups, Abelian Groups...................................... 42 2.12 Number Theory............................................. 43 2.13 Some More Advanced Mathematics................................... 46 3 The Interactive Shell 55 3.1 Your Sage Session............................................ 55 3.2 Logging Input and Output........................................ 57 3.3 Paste Ignores Prompts.......................................... 58 3.4 Timing Commands............................................ 58 3.5 Other IPython
    [Show full text]
  • Python Guide Documentation 0.0.1
    Python Guide Documentation 0.0.1 Kenneth Reitz 2015 11 07 Contents 1 3 1.1......................................................3 1.2 Python..................................................5 1.3 Mac OS XPython.............................................5 1.4 WindowsPython.............................................6 1.5 LinuxPython...............................................8 2 9 2.1......................................................9 2.2...................................................... 15 2.3...................................................... 24 2.4...................................................... 25 2.5...................................................... 27 2.6 Logging.................................................. 31 2.7...................................................... 34 2.8...................................................... 37 3 / 39 3.1...................................................... 39 3.2 Web................................................... 40 3.3 HTML.................................................. 47 3.4...................................................... 48 3.5 GUI.................................................... 49 3.6...................................................... 51 3.7...................................................... 52 3.8...................................................... 53 3.9...................................................... 58 3.10...................................................... 59 3.11...................................................... 62
    [Show full text]
  • Python Guide Documentation Publicación 0.0.1
    Python Guide Documentation Publicación 0.0.1 Kenneth Reitz 17 de May de 2018 Índice general 1. Empezando con Python 3 1.1. Eligiendo un Interprete Python (3 vs. 2).................................3 1.2. Instalando Python Correctamente....................................5 1.3. Instalando Python 3 en Mac OS X....................................6 1.4. Instalando Python 3 en Windows....................................8 1.5. Instalando Python 3 en Linux......................................9 1.6. Installing Python 2 on Mac OS X.................................... 10 1.7. Instalando Python 2 en Windows.................................... 12 1.8. Installing Python 2 on Linux....................................... 13 1.9. Pipenv & Ambientes Virtuales...................................... 14 1.10. Un nivel más bajo: virtualenv...................................... 17 2. Ambientes de Desarrollo de Python 21 2.1. Your Development Environment..................................... 21 2.2. Further Configuration of Pip and Virtualenv............................... 26 3. Escribiendo Buen Código Python 29 3.1. Estructurando tu Proyecto........................................ 29 3.2. Code Style................................................ 40 3.3. Reading Great Code........................................... 49 3.4. Documentation.............................................. 50 3.5. Testing Your Code............................................ 53 3.6. Logging.................................................. 57 3.7. Common Gotchas...........................................
    [Show full text]
  • Python Guide Documentation 0.0.1
    Python Guide Documentation 0.0.1 Kenneth Reitz 2015 09 13 Contents 1 Getting Started 3 1.1 Picking an Interpreter..........................................3 1.2 Installing Python on Mac OS X.....................................5 1.3 Installing Python on Windows......................................6 1.4 Installing Python on Linux........................................7 2 Writing Great Code 9 2.1 Structuring Your Project.........................................9 2.2 Code Style................................................ 15 2.3 Reading Great Code........................................... 24 2.4 Documentation.............................................. 24 2.5 Testing Your Code............................................ 26 2.6 Common Gotchas............................................ 30 2.7 Choosing a License............................................ 33 3 Scenario Guide 35 3.1 Network Applications.......................................... 35 3.2 Web Applications............................................ 36 3.3 HTML Scraping............................................. 41 3.4 Command Line Applications....................................... 42 3.5 GUI Applications............................................. 43 3.6 Databases................................................. 45 3.7 Networking................................................ 45 3.8 Systems Administration......................................... 46 3.9 Continuous Integration.......................................... 49 3.10 Speed..................................................
    [Show full text]