pyflakes: The Passive Checker of Python Programs
There are several code analysis tools for Python. The most well known is pylint. Then there’s pychecker and now we’re moving on to pyflakes. The pyflakes project is a part of something known as the Divmod Project. Pyflakes doesn’t actually execute the code it checks, unlike pychecker. Of course, pylint also doesn’t execute the code. Regardless, we’ll take a quick look at it and see how pyflakes works and if it’s better than the competition.
Getting Started
As you have probably guessed, pyflakes is not a part of the Python distribution. You will need to download it from PyPI or from the project’s launchpad page. Once you have it installed, you can run it against some of your own code. Or you can follow along and see how it works with our test script.
Running pyflakes
We’ll be using a super simple and pretty silly example script. In fact, it’s the same one we used for the pylint and pychecker articles. Here it is again for your viewing pleasure:
02.
03.########################################################################
04.class CarClass:
05.""""""
06.
07.#----------------------------------------------------------------------
08.def __init__(self, color, make, model, year):
09."""Constructor"""
10.self.color = color
11.self.make = make
12.self.model = model
13.self.year = year
14.
15.if "Windows" in platform.platform():
16.print "You're using Windows!"
17.
18.self.weight = self.getWeight(1, 2, 3)
19.
20.#----------------------------------------------------------------------
21.def getWeight(this):
22.""""""
23.return "2000 lbs"As was noted in the other articles, this dumb code has 4 issues, 3 of which would stop the programming from running. Let’s see what pyflakes can find! Try running the following command and you’ll see the following output:
crummy_code.py:1: 'sys' imported but unused
crummy_code.py:15: undefined name 'platform'While pyflakes was super fast at returning this output, it didn’t find all the errors. The getWeight method call is passing too many arguments and getWeight method itself is defined incorrectly as it doesn’t have a “self” argument. If you fixed your code according to what pyflakes told you, you’re code still wouldn’t work.
Getting Started
As you have probably guessed, pyflakes is not a part of the Python distribution. You will need to download it from PyPI or from the project’s launchpad page. Once you have it installed, you can run it against some of your own code. Or you can follow along and see how it works with our test script.
Running pyflakes
We’ll be using a super simple and pretty silly example script. In fact, it’s the same one we used for the pylint and pychecker articles. Here it is again for your viewing pleasure:
CODE:
01.import sys02.
03.########################################################################
04.class CarClass:
05.""""""
06.
07.#----------------------------------------------------------------------
08.def __init__(self, color, make, model, year):
09."""Constructor"""
10.self.color = color
11.self.make = make
12.self.model = model
13.self.year = year
14.
15.if "Windows" in platform.platform():
16.print "You're using Windows!"
17.
18.self.weight = self.getWeight(1, 2, 3)
19.
20.#----------------------------------------------------------------------
21.def getWeight(this):
22.""""""
23.return "2000 lbs"As was noted in the other articles, this dumb code has 4 issues, 3 of which would stop the programming from running. Let’s see what pyflakes can find! Try running the following command and you’ll see the following output:
CODE:
C:\Users\mdriscoll\Desktop>pyflakes crummy_code.pycrummy_code.py:1: 'sys' imported but unused
crummy_code.py:15: undefined name 'platform'While pyflakes was super fast at returning this output, it didn’t find all the errors. The getWeight method call is passing too many arguments and getWeight method itself is defined incorrectly as it doesn’t have a “self” argument. If you fixed your code according to what pyflakes told you, you’re code still wouldn’t work.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-733242/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ftp的passive模式FTP模式
- (譯)理解Rust的 borrow checkerRust
- [移動端新特性] Passive Event Listeners
- mac網站分析工具:SEO Checker for MacMac網站
- 基於 babel 手寫 ts type checkerBabel
- Razavi - RF Microelectronics的筆記 - Current-Driven Passive Mixer筆記
- 解決滾動警告:Unable to preventDefault inside passive event listenerIDE
- 關於passive event listener的一次踩坑
- java 英文單詞拼寫糾正框架(Word Checker)Java框架
- CF 2002 D1. DFS Checker (Easy Version) (*1900)思維
- Proj. CDeepFuzz Paper Reading: Checker Bug Detection and Repair in Deep Learning LibrariesAI
- Added non-passive event listener to ascroll- blocking ‘mousewheel‘event Consider marking event handlBloCIDE
- mpi4py安裝報錯error: Cannot compile MPI programs. Check your configuration!!!ErrorCompile
- C# 9.0 終於來了, Top-level programs 和 Partial Methods 兩大新特性探究C#
- percona-toolkit之pt-index-usage和pt-duplicate-key-checker詳解Index
- C#9.0新特性詳解系列之四:頂級程式語句(Top-Level Programs)C#
- iMobie M1 App Checker for Mac(是否支援M1應用檢測工具) v1.1.0免費版APPMac
- 【python】python安裝Python
- python ----python的安裝Python
- python:python的多程式Python
- python--- 之The program 'python' can be found in the following packages: * python-minimal * python3PythonPackage
- Python IDLE和Python的區別!Python入門教程Python
- python學習之初識pythonPython
- 【Python】python類的繼承Python繼承
- Python 序列化(Python IO)Python
- Python合集之Python函式Python函式
- pythonPython
- python _Python
- python教程(一)·python環境搭建Python
- 學習Python的日子 Python(6)Python
- [python] Python型別提示總結Python型別
- Python補充02 Python小技巧Python
- 小白自學Python(一) -- Python教程Python
- Python之將Python字串生成PDFPython字串
- Python 字串格式化(Python IO)Python字串格式化
- Python 檔案讀寫(Python IO)Python
- 『python入門:』 python的介紹Python
- 與 Python 之父聊天:更快的 Python!Python
- python(python中的super函式、)Python函式