Pycharm's code style inspection: ignore/switch off specific rules

前端 未结 5 627
悲哀的现实
悲哀的现实 2021-01-01 09:17

I\'m trying to import existing project into PyCharm. I can refactor the code so that PyCharm will be pleased, but we like to have spaces around colons in dictionaries, like

相关标签:
5条回答
  • 2021-01-01 09:20

    If you're ok to ignore all matching issues, you can just press Alt-Enter (or click on the lightbulb) and choose "Disable Inspection". Saves you going into the settings and trying to figure out the inspection rule that matches.

    From http://iambigblind.blogspot.jp/2013/02/configuring-pep8py-support-in-pycharm-27.html

    0 讨论(0)
  • 2021-01-01 09:27

    @Krzysztof Stanisławek, function is different as Pycharm follows the PEP8 coding style, so it is recommended that there is no whitespace between the function variables and ":", if you don't want this, you can disable it by

    "Settings"-> "Editor"-> "Inspections"->"PEP8 coding style violation"
    

    However, this is not recommended.

    0 讨论(0)
  • 2021-01-01 09:33

    Using PyCharm 5 (community edition), you can do the following: Code –> Inspect Code. Then select the required inspection error, and click on the "Suppress" option or "Ignore errors like this" option on right hand side. Please look at the screenshot below:

    When you choose the "Suppress" option, it adds a comment as shown in the screenshot below:

    Suppressing can be done at the statement, or function/method, levels. If trying to suppress an argument to a function, the suppression only works at the function level (meaning it also suppresses other name reference violations that might exist within that function).

    You also have the option of switching off "PEP8 coding style violations" altogether (by ticking the box shown below), or explicitly managing "Ignore Errors" manually. Screenshot given below:

    In general, you should perhaps question why you are suppressing PEP8 guidelines. However, sometimes it appears necessary, for instance when using the pytest module, it is necessary to shadow variables, etc, which the PEP8 Inspection complains about in. In such cases, this feature in PyCharm is very helpful.

    0 讨论(0)
  • 2021-01-01 09:45

    I got the same issue, and the neat solution has been pointed by @fantabolous, from configuring PEP8.py support in PyCharm 2.7

    Example before

    Adding the error code either manually or with "Alt+Enter" on error highlight
    The error code can be found here

    After the changes

    It's great to select precisely some rules instead of disabling all warning from PEP8. Thanks to the previous comments.

    0 讨论(0)
  • 2021-01-01 09:46

    to have spaces around colons in dictionaries, configure Settings > Editor > Python Spaces

    Other > Before ':'

    and

    Other > After ':'

    0 讨论(0)
提交回复
热议问题