Where are detailed the rules, concepts and usages behind each pylint's warnings?

北城余情 提交于 2019-12-25 18:19:51

问题


I am still discovering Pylint and I understand why many Pythonists deactivate some (or many) warnings to lower Pylint's voice, but for the moment, as a Python newbie I want to use pylint to improve my Pythonic comprehension and my code quality, in order to help me to:

  • learning more from a statement/instruction
  • deepen some concepts
  • evaluate the benefits / drawback of a refactoring
  • etc.

So is there a place where all the warning are discussed, justified, explained or they simply came from the great minds of the pylint team?


回答1:


Ok, thanks for answers.

I like using pylint to help me coding better and I was hoping that the pylint project explains and arguments somewhere the warnings with details useful for beginners like me: helping to:

  • understand why it is important to consider these warnings
  • when a certain context can moderate the point of view
  • when it came from a PEP
  • etc.

It looks like it is not the case.

Anyway, although it is really not filled-in/detailed enough, Pylint messages (which I found before asking my question) remain the least bad answer to my question.




回答2:


Answering to your comment:

When I have some warnings I'd like to know a bit more than "too many 'whatever'", "invalid 'something'", etc. If my code work fine I assume these warnings are kind of guide lines and mays be studied with the context. For syntax, I refer on PEP8, but for the other warnings? OK all warning do not have a PEP. Why the max branch is set to 15, statements is set to 50, variables set to 15, etc. ?

Those are mostly based on "best practices" - "golden rules" which are mostly derived from experience but can err a bit on the arbitrary side sometimes - and actually the numbers you mention are indeed arbitrary but you do have to set an arbitrary limit here, at least until pylint grows and IA.

If python accept to run the code what is the point…?

Because code has to be maintained - you typically spend hundreds more time maintaining code (fixing bugs, improving performances and adding features) than writing the first version -, and small, well decoupled, simple functions doing one single thing are easier to read, understand, reason about and test than overly long functions doing three different things at once and implemented with deeply nested branches and lots of side effects.

Now as I mentionned the numbers you mention are indeed arbitrary and may or not be appropriate for a given part of your code. Some functions are intrisincally complex and require more complex code, and you need both programming experience and a good enough knowledge of the problem to assess your code quality.

Pylint can only warn you about things that might be code smells, it's up to you to decide if the code can be improved or if it's ok (and then possibly turn off some warnings for a given statemement or function or module etc). Also there are code smells that pylint can't really detect - like a function doing too many different things - so you still have to re-read your code and ask yourself if it's ok or not. Testability is a good indicator here, if you cannot easily unittest a function then chances are it's doing too many things - but here again some parts of the code (the ones that bridges UI and domain for example) are by definition harder to unittest so here again you do have to use your own judgment.




回答3:


When I enter pylint warnings into a web (google) search bar, the first hit is PyLint Messages, with a link to a page explaining each message.



来源:https://stackoverflow.com/questions/49238036/where-are-detailed-the-rules-concepts-and-usages-behind-each-pylints-warnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!