Descriptors, magic methods, and inheritance: oh my! on Nov. 19, 2017 at 4:20 p.m. in R-M120

It's very simple to write straightforward imperative code with Python. You can easily define classes and functions, and write behavior inside them. However, pure imperative design means that you'll likely end up writing the same patterns of code over and over - whether it's requests.get() or LOGGER = getLogger(__name__). By taking advantage of some of the more advanced features of the Python language, like descriptors, overridden magic methods, and creative uses of inheritance, we can make our code smaller and more expressive. Proper abstractions will also make it easier to test your code thoroughly and effectively - because you're not reimplementing behavior unnecessarily, you can properly test the one place you do implement it, and rely on it from then on. And, it becomes much easier to add features later on that rely on existing behavior - you just need to describe them in terms of the things you've already implemented.


Jesse Shapiro

Jesse Shapiro is a senior open sourcerer focusing full-time on the Open edX online learning platform. Jesse is also a member of the core team for the urllib3 project, which plays an essential part in Requests, pip, and most other Python HTTP libraries. Jesse's own projects include the now-defunct beekeeper API client builder and kodipydent, a library to make interacting with the Kodi JSON-RPC API easier to do. He lives in Boston with his much-smarter partner, and loves baking, working on his homebrew home theater and home automation systems, and messing with arcane aspects of Python to try to find new API paradigms. Jesse's preferred pronouns are he/him/his.