{"id":162627,"date":"2019-11-26T12:00:20","date_gmt":"2019-11-26T04:00:20","guid":{"rendered":"https:\/\/gulass.cn\/?p=162627"},"modified":"2019-10-28T08:59:16","modified_gmt":"2019-10-28T00:59:16","slug":"pylint-python-linux","status":"publish","type":"post","link":"https:\/\/gulass.cn\/pylint-python-linux.html","title":{"rendered":"Pylint\uff1a\u66f4\u9ad8\u5c42\u7ea7\u7684 Python \u6837\u5f0f\u5f3a\u5236\u7a0b\u5e8f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5f53\u4f60\u60f3\u8981\u4e89\u8bba\u4ee3\u7801\u590d\u6742\u6027\u65f6\uff0cPylint \u662f\u4f60\u7684\u670b\u53cb\u3002Pylint \u662f\u66f4\u9ad8\u5c42\u7ea7\u7684 Python \u6837\u5f0f\u5f3a\u5236\u7a0b\u5e8f\u3002\u800c flake8 \u548c black \u68c0\u67e5\u7684\u662f\u201c\u672c\u5730\u201d\u6837\u5f0f\uff1a\u6362\u884c\u4f4d\u7f6e\u3001\u6ce8\u91ca\u7684\u683c\u5f0f\u3001\u53d1\u73b0\u6ce8\u91ca\u6389\u7684\u4ee3\u7801\u6216\u65e5\u5fd7\u683c\u5f0f\u4e2d\u7684\u9519\u8bef\u505a\u6cd5\u4e4b\u7c7b\u7684\u95ee\u9898\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPylint \u975e\u5e38\u6fc0\u8fdb\u3002\u5b83\u5c06\u5bf9\u6bcf\u6837\u4e1c\u897f\u90fd\u63d0\u4f9b\u4e25\u5389\u7684\u610f\u89c1\uff0c\u4ece\u68c0\u67e5\u662f\u5426\u5b9e\u9645\u5b9e\u73b0\u58f0\u660e\u7684\u63a5\u53e3\u5230\u91cd\u6784\u91cd\u590d\u4ee3\u7801\u7684\u53ef\u80fd\u6027\uff0c\u8fd9\u5bf9\u65b0\u7528\u6237\u6765\u8bf4\u53ef\u80fd\u4f1a\u5f88\u591a\u3002\u4e00\u79cd\u6e29\u548c\u5730\u5c06\u5176\u5f15\u5165\u9879\u76ee\u6216\u56e2\u961f\u7684\u65b9\u6cd5\u662f\u5148\u5173\u95ed\u6240\u6709\u68c0\u67e5\u5668\uff0c\u7136\u540e\u9010\u4e2a\u542f\u7528\u68c0\u67e5\u5668\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u5728\u4f7f\u7528 flake8\u3001black \u548c mypy\uff0c\u8fd9\u5c24\u5176\u6709\u7528\uff1aPylint \u6709\u76f8\u5f53\u591a\u7684\u68c0\u67e5\u5668\u548c\u5b83\u4eec\u5728\u529f\u80fd\u4e0a\u91cd\u53e0\u3002<\/p>\n

\u4f46\u662f\uff0cPylint \u72ec\u6709\u4e4b\u5904\u4e4b\u4e00\u662f\u80fd\u591f\u5f3a\u5236\u6267\u884c\u66f4\u9ad8\u7ea7\u522b\u7684\u95ee\u9898\uff1a\u4f8b\u5982\uff0c\u51fd\u6570\u7684\u884c\u6570\u6216\u8005\u7c7b\u4e2d\u65b9\u6cd5\u7684\u6570\u91cf\u3002<\/p>\n

\u8fd9\u4e9b\u6570\u5b57\u53ef\u80fd\u56e0\u9879\u76ee\u800c\u5f02\uff0c\u5e76\u4e14\u53ef\u80fd\u53d6\u51b3\u4e8e\u5f00\u53d1\u56e2\u961f\u7684\u504f\u597d\u3002\u4f46\u662f\uff0c\u4e00\u65e6\u56e2\u961f\u5c31\u53c2\u6570\u8fbe\u6210\u4e00\u81f4\uff0c\u4f7f\u7528\u81ea\u52a8\u5de5\u5177\u5f3a\u5236\u5316\u8fd9\u4e9b\u53c2\u6570\u975e\u5e38\u6709\u7528\u3002\u8fd9\u662f Pylint \u95ea\u8000\u7684\u5730\u65b9\u3002<\/p>\n

\u914d\u7f6e Pylint<\/strong><\/div>\n

\u8981\u4ee5\u7a7a\u914d\u7f6e\u5f00\u59cb\uff0c\u8bf7\u5c06 .pylintrc \u8bbe\u7f6e\u4e3a<\/p>\n

[MESSAGES CONTROL]\r\ndisable=all<\/pre>\n

\u8fd9\u5c06\u7981\u7528\u6240\u6709 Pylint \u6d88\u606f\u3002\u7531\u4e8e\u5176\u4e2d\u8bb8\u591a\u662f\u5197\u4f59\u7684\uff0c\u8fd9\u662f\u6709\u9053\u7406\u7684\u3002\u5728 Pylint \u4e2d\uff0cmessage \u662f\u4e00\u79cd\u7279\u5b9a\u7684\u8b66\u544a\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c pylint \u6765\u786e\u8ba4\u6240\u6709\u6d88\u606f\u90fd\u5df2\u5173\u95ed\uff1a<\/p>\n

$ pylint <\/my><\/pre>\n

\u901a\u5e38\uff0c\u5411 pylint \u547d\u4ee4\u884c\u6dfb\u52a0\u53c2\u6570\u5e76\u4e0d\u662f\u4e00\u4e2a\u597d\u4e3b\u610f\uff1a\u914d\u7f6e pylint \u7684\u6700\u4f73\u4f4d\u7f6e\u662f .pylintrc\u3002\u4e3a\u4e86\u4f7f\u5b83\u505a\u4e00\u4e9b\u6709\u7528\u7684\u4e8b\uff0c\u6211\u4eec\u9700\u8981\u542f\u7528\u4e00\u4e9b\u6d88\u606f\u3002<\/p>\n

\u8981\u542f\u7528\u6d88\u606f\uff0c\u5728 .pylintrc \u4e2d\u7684 [MESSAGES CONTROL] \u4e0b\u6dfb\u52a0<\/p>\n

enable=,\r\n       ...<\/message><\/pre>\n

\u5bf9\u4e8e\u770b\u8d77\u6765\u6709\u7528\u7684\u201c\u6d88\u606f\u201d\uff08Pylint \u79f0\u4e4b\u4e3a\u4e0d\u540c\u7c7b\u578b\u7684\u8b66\u544a\uff09\u3002\u6211\u6700\u559c\u6b22\u7684\u5305\u62ec too-many-lines\u3001too-many-arguments \u548c too-many-branches\u3002\u6240\u6709\u8fd9\u4e9b\u4f1a\u9650\u5236\u6a21\u5757\u6216\u51fd\u6570\u7684\u590d\u6742\u6027\uff0c\u5e76\u4e14\u65e0\u9700\u8fdb\u884c\u4eba\u5de5\u64cd\u4f5c\u5373\u53ef\u5ba2\u89c2\u5730\u8fdb\u884c\u4ee3\u7801\u590d\u6742\u5ea6\u6d4b\u91cf\u3002<\/p>\n

\u68c0\u67e5\u5668\u662f\u6d88\u606f\u7684\u6765\u6e90\uff1a\u6bcf\u6761\u6d88\u606f\u53ea\u5c5e\u4e8e\u4e00\u4e2a\u68c0\u67e5\u5668\u3002\u8bb8\u591a\u6700\u6709\u7528\u7684\u6d88\u606f\u90fd\u5728\u8bbe\u8ba1\u68c0\u67e5\u5668\u4e0b\u3002\u9ed8\u8ba4\u6570\u5b57\u901a\u5e38\u90fd\u4e0d\u9519\uff0c\u4f46\u8981\u8c03\u6574\u6700\u5927\u503c\u4e5f\u5f88\u7b80\u5355\uff1a\u6211\u4eec\u53ef\u4ee5\u5728 .pylintrc \u4e2d\u6dfb\u52a0\u4e00\u4e2a\u540d\u4e3a DESIGN \u7684\u6bb5\u3002<\/p>\n

[DESIGN]\r\nmax-args=7\r\nmax-locals=15<\/pre>\n

\u53e6\u4e00\u4e2a\u6709\u7528\u7684\u6d88\u606f\u6765\u6e90\u662f\u201c\u91cd\u6784\u201d\u68c0\u67e5\u5668\u3002\u6211\u5df2\u542f\u7528\u4e00\u4e9b\u6700\u559c\u6b22\u7684\u6d88\u606f\u6709 consider-using-dict-comprehension\u3001stop-iteration-return\uff08\u5b83\u4f1a\u67e5\u627e\u6b63\u786e\u7684\u505c\u6b62\u8fed\u4ee3\u7684\u65b9\u5f0f\u662f return \u800c\u4f7f\u7528\u4e86 raise StopIteration \u7684\u8fed\u4ee3\u5668\uff09\u548c chained-comparison\uff0c\u5b83\u5c06\u5efa\u8bae\u4f7f\u7528\u5982 1 < = x < 5\uff0c\u800c\u4e0d\u662f\u4e0d\u592a\u660e\u663e\u7684 1 <= x && 5 > 5 \u7684\u8bed\u6cd5\u3002<\/p>\n

\u6700\u540e\u662f\u4e00\u4e2a\u5728\u6027\u80fd\u65b9\u9762\u6d88\u8017\u5f88\u5927\u7684\u68c0\u67e5\u5668\uff0c\u4f46\u5b83\u975e\u5e38\u6709\u7528\uff0c\u5c31\u662f similarities\u3002\u5b83\u4f1a\u67e5\u627e\u4e0d\u540c\u90e8\u5206\u4ee3\u7801\u4e4b\u95f4\u7684\u590d\u5236\u7c98\u8d34\u6765\u5f3a\u5236\u6267\u884c\u201c\u4e0d\u8981\u91cd\u590d\u81ea\u5df1\u201d\uff08DRY \u539f\u5219\uff09\u3002\u5b83\u53ea\u542f\u7528\u4e00\u6761\u6d88\u606f\uff1aduplicate-code\u3002\u9ed8\u8ba4\u7684 \u201c\u6700\u5c0f\u76f8\u4f3c\u884c\u6570\u201d \u8bbe\u7f6e\u4e3a 4\u3002\u53ef\u4ee5\u4f7f\u7528 .pylintrc \u5c06\u5176\u8bbe\u7f6e\u4e3a\u4e0d\u540c\u7684\u503c\u3002<\/p>\n

[SIMILARITIES]\r\nmin-similarity-lines=3<\/pre>\n
Pylint \u4f7f\u4ee3\u7801\u8bc4\u5ba1\u53d8\u5f97\u7b80\u5355<\/strong><\/div>\n

\u5982\u679c\u4f60\u538c\u5026\u4e86\u9700\u8981\u6307\u51fa\u4e00\u4e2a\u7c7b\u592a\u590d\u6742\uff0c\u6216\u8005\u4e24\u4e2a\u4e0d\u540c\u7684\u51fd\u6570\u57fa\u672c\u76f8\u540c\u7684\u4ee3\u7801\u8bc4\u5ba1\uff0c\u8bf7\u5c06 Pylint \u6dfb\u52a0\u5230\u4f60\u7684\u6301\u7eed\u96c6\u6210\u914d\u7f6e\u4e2d\uff0c\u5e76\u4e14\u53ea\u9700\u8981\u5bf9\u9879\u76ee\u590d\u6742\u6027\u51c6\u5219\u7684\u4e89\u8bba\u4e00\u6b21\u5c31\u884c\u3002<\/p>\n

via: https:\/\/opensource.com\/article\/19\/10\/python-pylint-introduction<\/p>\n

\u4f5c\u8005\uff1aMoshe Zadka \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1ageekpi \u6821\u5bf9\uff1awxy<\/p>\n

\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPylint \u975e\u5e38\u6fc0\u8fdb\u3002\u5b83\u5c06\u5bf9\u6bcf\u6837\u4e1c\u897f\u90fd\u63d0\u4f9b\u4e25\u5389\u7684\u610f\u89c1\uff0c\u4ece\u68c0\u67e5\u662f\u5426\u5b9e\u9645\u5b9e\u73b0\u58f0\u660e\u7684\u63a5\u53e3\u5230\u91cd\u6784\u91cd\u590d\u4ee3\u7801 […]<\/p>\n","protected":false},"author":1482,"featured_media":113018,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-162627","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/162627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=162627"}],"version-history":[{"count":5,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/162627\/revisions"}],"predecessor-version":[{"id":162653,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/162627\/revisions\/162653"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/113018"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=162627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=162627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=162627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}