How to Patch Requests to Have a Default Timeout

Python’s requests
package is very popular. Even if you don’t use it directly, it’s highly likely one of your dependencies does.
Adam Johnson
Home | Blog | Books | Projects | Colophon | Contact
(All tags.)
Python’s requests
package is very popular. Even if you don’t use it directly, it’s highly likely one of your dependencies does.
I joined host Tobias Macey on Podcast.__init__, in Episode 349, published this monday. The episode is titled “Improve Your Productivity By Investing In Developer Experience Design For Your Projects”. We covered various topics related to “developer experience” and general ways to improve it on any Python project.
Here’s a small problem I’ve seen where several modules share versions of the same “constant” variable. It came up in the context of a Django project with multiple settings files, but it could happen in different contexts.
The typing
module continues to evolve, with new features in every Python version. This can make it tricky if you’re trying to type code that supports multiple Python versions. To help write such code, Mypy identifies version checks using sys.version_info
and reads the appropriate branch.
Here’s an innocent enough looking Python file:
SimpleNamespace
When testing Python code you may need a mock object. That’s okay! But what’s the best way to build a simple mock?
On Monday I released my new book “Boost Your Django DX”. It covers many tools and practices that are useful for developing Django projects.
Python 3.6 reached its end of life on the 23rd December. As its release manager put on the Python forum, it has gracefully “ridden off into the sunset”.
Python’s built-in collection types come in mutable and immutable flavours, but one is conspicuously missing:
This post is not about importing typing.Optional
, but instead imports that are themselves optional. Libraries often have optional dependencies, and the code should work whether or not the import is there. A common pattern to solve this to catch ImportError
and replace the module with None
: