Python – ny way to fix PEP-8 issues with pydev

pydevpython

I want to know if there is any way to fix all the PEP-8 issues automatically with a keyboard shortcut in eclipse-pydev. Googling did not get me anywhere.

Since Pydev can detect the PEP-8 issues, should it not be possible to fix them automatically?

Best Answer

You can manually activate the PyDev code-formatter with Ctrl+Shift+F (preferences at: Window > Preferences > PyDev > Editor > Code Style > Code Formatter -- note that you can configure it to run automatically under Window > Preferences > PyDev > Editor > Save Actions).

Note that the internal PyDev code-formatter is pretty conservative and won't do all transformations required for 100% compatible PEP8 code (although it handles the more common cases), so, if it's not enough for your needs, you have some options:

  1. You can use autopep8.py or black which are also integrated into PyDev by default in the latest version (Enabled via Window > Preferences > PyDev > Editor > Code Style > Code Formatter > Formatter Style? and then select autopep8 or black).

  2. You can take a look at PythonTidy (external tool)... it's possible to use it as defined in: http://bear330.wordpress.com/2007/10/30/using-pythontidy-in-pydev-as-code-formatter/