Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Who Are You, Really?

In this lesson, you’ll learn what introspection is and how it can be used to get more information about a Python function. You’ll also see that introspecting decorated functions can be a little confusing because of the way the functions identify themselves after decoration. To solve this problem, you will learn how to use @functools.wraps, a decorator from the functools module which updates special attributes used for introspection.

Dirk on March 26, 2019

Should I always import functools whenever I use decorators?

Geir Arne Hjelle RP Team on March 26, 2019

Hi Dirk,

it’ll be a good practice to use @functools.wraps when you create your own decorators. One exception is when you return the original function untouched as is done in the Registering Plugins With Decorators example.

Also, there is the functools.update_wrapper() function which @functools.wraps uses under the hood. There are some cases when calling the function directly gives you some added flexibility. One example is when your decorator is implemented as a class instead of a function: realpython.com/primer-on-python-decorators/#classes-as-decorators

Dirk on March 26, 2019

Thanks Geir!

Become a Member to join the conversation.