Using Decorators to Improve Our Code

In this chapter, we will explore decorators and see how they are useful in many situations where we want to improve our design. We will start by first exploring what decorators are, how they work, and how they are implemented.

With this knowledge, we will then revisit concepts that we learned in previous chapters regarding general good practices for software design, and see how decorators can help us comply with each principle.

The goals of this chapter are as follows:

  • To understand how decorators work in Python
  • To learn how to implement decorators that apply to functions and classes
  • To effectively implement decorators, avoiding common implementation mistakes
  • To analyze how to avoid code duplication (the ...

Get Clean Code in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.