Sometimes people do funky things with data. We have a use case where two two-digit codes are mashed together into a four-digit code, and we need to split them. These codes are stored as integers because, well, why not.
If you’ve ever written unit tests, you’ve probably encountered situations where a function depends on an external API, a database, or a cloud service. These things are difficult to control in a test environment. This is where mocking comes in.
In this article we describe how a need for parsing Python files led us on a journey starting with plain text parsing, to abstract syntax trees, and then finally to where we wound up with conrete syntax trees, and the lessons we learned along the way.
I’m definitely a fan of list comprehensions in Python (as well as dict comprehensions), but I have some pretty specific ideas about how they should be formatted to be readable. Dict comprehensions are more complex, but even the much simpler list comprehensions can be abused, or misleading even when used well.