Protip: Enable deprecation warnings in Python

Protip: Enable deprecation warnings in Python

Since version 2.7, Python no longer outputs anything when a deprecation warning is hit. This is a good idea if you are running apps that use Python internally as you might not care about this sort of thing. However, it’s a bad idea if you are developing in Python yourself (as opposed to just using an application that was written in Python).

You can turn them back on by either (1) passing -Wd on the command line, or (2) setting the PYTHONWARNINGS environmental variable to d. In fact, this allows you to just set this option in your .bashrc (or.zshrc):

export PYTHONWARNINGS=d

Now, all your Python will warn you about deprecations, which you should care about as a developer.

§

I only discovered this myself a few days ago, but have since already stumbled upon several deprecated usages in my code.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s