Debugging in Python, part 6: Tracebacks with dependencies

MP 145: Why third-party code appears in tracebacks, and what you can learn from it.

Note: This post is part of an ongoing series about debugging in Python. The posts in this series will only be available to paid subscribers for the first 6 weeks. After that they will be available to everyone. Thank you to everyone who supports my ongoing work on Mostly Python.

The code we've focused on so far in this series didn't have any external dependencies. But that's not representative of most real-world Python code; almost all the code we write relies on multiple third-party packages.

When your project doesn't have any dependencies, everything in a traceback relates to code you've written. When you're using third-party packages, code from those dependencies can show up in a traceback. While most bugs come from our own code, the presence of these extra lines in the traceback can make the debugging process seem more complicated.

In this post we'll introduce some errors into a small program that uses two third-party packages. We'll look at how code from a dependency can show up in a traceback, and see how to make sense of the increased volume of information.

Diving further into music

I've been learning piano for a little while now, and a lot of the disconnected ideas I learned about music when I was younger are starting to make sense for the first time. Inspired by that, I recently picked up an electric guitar. I tried to learn when I was younger, but I didn't really know how to learn, I didn't know how to practice, and there were no musical people in my immediate sphere. Things feel different now, and I feel like I might finally be able to play well.

Ibanez electric guitar on floor stand
I liked metal guitars as a kid, but as an adult I want to learn on a more classic instrument. I won't splurge on a Fender Strat yet, but I was very happy to find a decent moderately-priced Strat-style guitar to see if I get very far.

When I was younger I just wanted to play metal. But as an adult people who play really well with a clean tone have grabbed my attention. So I picked up an entry-level Strat-style guitar. (Today's entry-level guitars are way nicer than entry-level instruments in the 80s.) It's been so much fun to play, and I'm understanding it much better than I used to.

Someone recently asked about how to visualize people's attendance in a meeting. After making a quick demo plot in response to that question, I wanted to build a visualization of the lifespans of the famous Fender Strat players I was starting to pay more attention to.

Player lifespans

A visualization like this is a slightly customized horizontal bar chart. First, we need some data; here's the code representing the data for each player:

This post is only available to paid subscribers at the moment. It will be available to everyone 6 weeks after posting. If you'd like to continue reading now, please support my work by signing up for a paid subscription.

Paid subscription options