Length hints in Python

I was grubbing about trying to understand some library code the other day (I forget which one) and I came across a double-underscore method I’d never seen before: def __length_hint__(self): return … # Some internals here. Since this is a double-underscore method, it can’t be (or shouldn’t be) something the library invented. It must have […]

How does q work?

In a previous post I talked about what you can do with the debug logging library q. It has some interesting features that don’t look like standard Python, though of course it all is. Debug anywhere Start with the simple things. One of the nice things about q is that you can stick a debug […]

How import works differently in Python 3.5

I messed up at work recently. We (a small start-up) have a staging server and a production server. Nothing gets deployed into production until it’s run on staging for a while and seems to be solid. But still I managed to mess this up. The problem started when I upgraded the deployment from Python 3.4 […]

How does coverage measurement work in Python?

If you’re writing serious Python you’re hopefully testing it, and if you’re doing any serious testing you are hopefully measuring how much code coverage you have. But how does code coverage measurement actually work? If I execute a test function and get back a result, how can I possibly tell which lines of code were […]