1. 程式人生 > >有選擇的忽略PyCharm 3的PEP8語言風格警告提示資訊

有選擇的忽略PyCharm 3的PEP8語言風格警告提示資訊

最近略嘗試了JetBrains的Python開發套件(IDE)PyCharm 3,感覺各方面還算強大,況且JetBrains也釋出免費的版本,喜歡嚐鮮的朋友不妨試試。

在使用過程中有一點不爽的就是基於PEP8.py的語言風格提示,我看了下,大多數語言風格糾正提示值得我們參考,但是有一些我持保留態度,在團隊約定俗成程式碼風格後基本就不用受其他約束了,當然PyCharm好心的PEP8提示卻有礙程式碼觀感,怎樣才能關閉我不需要的警告資訊呢?

求助於萬能的Google,找到了這一篇文章《configuring PEP8.py support in PyCharm 2.7》(國內可能無法訪問),作者列出了以下步驟:

In pycharm, click the settings icon, or go to the settings via the menu bar.
In the project settings section, click ‘inspections’
In the list that appears, click ‘python’.
Under python, scroll down and click PEP8.
Now, underneath the description, you’ll se an ‘ignore errors’ section. Click the + at the bottom.
Now, gohere. This is a page of the pep8.py documentation, listing all possible errors and warnings.
Find an error you want to ignore, and copy the error code at the left.
Paste this error code into the field you just added in the settings window.
Add all the errors you want to ignore and click apply.

主要是在PyCharm專案設定中找到inspections選項,然後找到PEP 8 coding style violation,在右邊的ignore errors,點選下面的加號,新增要忽略的警告資訊編碼,這個編碼可以參考PEP8.py的官方網站,如下圖所示我添加了E221、E401、E203這幾個要忽略的資訊。

後來JetBrains的開發者Dmitry Jemerov與作者聯絡提供了一個更為簡便的辦法,那就是點選要忽略的錯誤所在,然後按Alt+Enter,在彈出下拉選單選擇ignore errors like this,就可以快速忽略了。