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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle Applications Interface ProgramsOracleAPP
- ftp的passive模式FTP模式
- (譯)理解Rust的 borrow checkerRust
- passive 的事件監聽器事件
- Oracle RAC active-passive modeOracle
- 全面學習ORACLE Scheduler特性(3)使用ProgramsOracle
- [移動端新特性] Passive Event Listeners
- 基於 babel 手寫 ts type checkerBabel
- mac網站分析工具:SEO Checker for MacMac網站
- Unable to preventDefault inside passive event listenerIDE
- get的被動用法(get-passive)
- MySQL pt-duplicate-key-checker工具使用初探MySql
- Async Console Programs 非同步控制檯程式非同步
- 關於passive event listener的一次踩坑
- java 英文單詞拼寫糾正框架(Word Checker)Java框架
- ES6 的功能偵測庫 ES-Checker
- Razavi - RF Microelectronics的筆記 - Current-Driven Passive Mixer筆記
- iOS-private-api-checker私有API檢查詳細步驟(涉及到 Python、Flask、sqlite 環境)iOSAPIPythonFlaskSQLite
- 解決滾動警告:Unable to preventDefault inside passive event listenerIDE
- MySQL使用pt-duplicate-key-checker找出冗餘、重複索引MySql索引
- 全面學習ORACLE Scheduler特性(5) Schedules排程Programs執行的JobsOracle
- 全面學習ORACLE Scheduler特性(5)Schedules排程Programs執行的JobsOracle
- pt-duplicate-key-checker檢查資料庫的重複索引資料庫索引
- EdgeRank Checker:Facebook專頁應間隔3小時釋出資訊
- How To Install An Oracle Database In An Active/Passive Configuration Without RAC? [ID 734361.1]OracleDatabase
- How To Setup ASM (11.2) On An Active/Passive Cluster (Non-RAC). [ID 1296124.1]ASM
- CF 2002 D1. DFS Checker (Easy Version) (*1900)思維
- Proj. CDeepFuzz Paper Reading: Checker Bug Detection and Repair in Deep Learning LibrariesAI
- C# 9.0 終於來了, Top-level programs 和 Partial Methods 兩大新特性探究C#
- percona-toolkit之pt-index-usage和pt-duplicate-key-checker詳解Index
- How To Setup ASM (10.2 & 11.1) On An Active/Passive Cluster (Non-RAC). [ID 1319050.1]ASM
- C#9.0新特性詳解系列之四:頂級程式語句(Top-Level Programs)C#
- mpi4py安裝報錯error: Cannot compile MPI programs. Check your configuration!!!ErrorCompile
- Added non-passive event listener to ascroll- blocking ‘mousewheel‘event Consider marking event handlBloCIDE
- iMobie M1 App Checker for Mac(是否支援M1應用檢測工具) v1.1.0免費版APPMac
- OpenStack高可用 -- DRBD塊映象 + Pacemaker心跳機制實現Active/Passive模式的高可用mysql叢集 ( by quqi99 )模式MySql
- 【python】python安裝Python
- 【Python】Python使用redisPythonRedis