Skip to main content

3 docs tagged with "decorators"

View all tags

Decorators (Part 1): Introduction to Decorators

Welcome to the final topic in our series on advanced Python concepts: decorators. Decorators are one of the most powerful and widely used features in Python, especially in web frameworks like Flask and Django. They might seem magical at first, but they are built directly on top of concepts we already know.

Decorators (Part 2): Decorators with Arguments

In our last article, we learned that a decorator is a function that wraps another function to add new behavior. However, our first decorator was simple: it only worked on functions that took no arguments.

The `functools` Module: `wraps` and `lru_cache`

We've learned how to create robust decorators that can wrap any function. As we saw, a key part of that pattern is using @functools.wraps to preserve the original function's metadata. The functools module is part of Python's standard library and contains powerful tools for working with higher-order functions (functions that act on or return other functions).