Catching Syntax Errors and More
Flycheck is an amazingly useful package for finding programming errors in real-time, and it supports a number of languages right out of the box, including Python. It saves time to be able to see that I’ve made a syntax error or something while writing the code instead of finding out later when I actually run that code.
There are a lot of third-party extensions for Flycheck out there, adding or improving support for different languages. I recommend the following for Python:
flycheck-mypy: Recently I wrote about static type-checking in Python using Mypy. This package allows Flycheck to use Mypy to catch type-errors in my code as I write it. It’s not useful for all projects, e.g. anything using Python 2 which Mypy doesn’t support, but when available I’ve found it to be an invaluable tool.
Live-py-mode is a package for Emacs (and Eclipse) which lets you see the results of your Python code in another window as you write it. Effectively it’s like Python running as an "inferior process" while automatically sending all of my code to it, instead of having to use some of Python Mode’s built-in commands like
I recommend watching this video to see just what you can do with live-py-mode.
I’m a fan of Helm, so I use helm-pydoc for quickly looking up documentation on Python modules and libraries. The package can do more than simply bring up documentation though. As you’ll see it also lets me open up the source code for packages or import them into the current buffer using either the
import ... or
from ... import ... syntax if I want.
The pytest.el package provides a collection of useful commands for running pytest, which I use on most Python projects. If you use Hydra for managing key-bindings then you may find my personal Hydra for pytest.el to be useful:
(define-key python-mode-map (kbd "C-c C-y") (defhydra hydra-pytest (:color blue) "pytest" ("a" pytest-all "all") ("m" pytest-module "module") ("o" pytest-one "one") ("d" pytest-directory "directory")))
The Big One
Anaconda is a package which adds a lot of functionality for Python programming. To quote the project page, its features include:
- context-sensitive code completion
- jump to definitions
- find references
- view documentation
- virtual environment
- eldoc mode
If you want a big chunk of additional Python programming features in a single package then you can probably do no better than to use Anaconda. (Edit: I forgot about Elpy, see the comments below.) And if you use Company for auto-completion, which I personally do, then you will also want the Anaconda backend for Company.