Tag: Decorators

  • Stop fearing Python decorators

    If I mention “decorators,” even if you’ve been programming with Python for a while, what comes to mind? To many, decorators are mysterious and powerful — and beyond the reach of mere mortals. Their @ signs pop up in all sorts of places, from “pytest” to Flask to properties… but it’s not really clear what…

    Read more

  • Making your Python decorators even better, with functool.wraps

    Summary: Decorate your inner wrapper function with @wraps(func), imported from functools, and the decorated function keeps its original name, docstring, and signature. Without it, help() and name report “wrapper” and a generic (*args, **kwargs) signature. It’s one line of code, and I recommend adding it to every decorator you write. The good news: I gave…

    Read more

  • Get code + slides from my “Practical Decorators” talk from Euro Python / PyCon 2019

    I presented my “Practical Decorators” talk twice this year — once at PyCon 2019 in Cleveland, and again at EuroPython 2019 in Basel. Here is the video of my presentation in Cleveland: If you want to get the PDF of my slides, as well as the Python code that I showed, then just enter your…

    Read more