A very clear presentation of a topic that I don’t find particularly intuitive. Thanks!! I want to play around more now to see what kinds of changes decorators can make.
The last example (return_type decorator) seems like a nice way to strictly enforce types in function arguments without too much of hassle. Type hints are great (and amazing with respect to readability), but it does not ensure runtime validation of types, while this seems to do the trick just fine. Wasn't expecting to walk out of this video with this. Thanks!
That's one of the reasons I'm not a fan of python's type system, because it largely is just a hint without additional tooling. If you find any other awesome decorator uses, come back and let us know!
Why couldn't add_attributes take the func by itself? Why does it need the decorator function? Before this video, I didn't even know decorators were a thing in Python.
Great question! An important thing to keep in mind is that the actual decorator only ever takes one argument, and that is the function it is decorating. So in order for us to build in this customized behavior we write the add_attributes function. This is what creates and returns the actual decorator at runtime.
A very clear presentation of a topic that I don’t find particularly intuitive.
Thanks!!
I want to play around more now to see what kinds of changes decorators can make.
I'm happy to see that you took my advice and did the one on decorators! well done! :)
great explanation
The last example (return_type decorator) seems like a nice way to strictly enforce types in function arguments without too much of hassle. Type hints are great (and amazing with respect to readability), but it does not ensure runtime validation of types, while this seems to do the trick just fine. Wasn't expecting to walk out of this video with this. Thanks!
That's one of the reasons I'm not a fan of python's type system, because it largely is just a hint without additional tooling.
If you find any other awesome decorator uses, come back and let us know!
Why couldn't add_attributes take the func by itself? Why does it need the decorator function?
Before this video, I didn't even know decorators were a thing in Python.
Great question! An important thing to keep in mind is that the actual decorator only ever takes one argument, and that is the function it is decorating. So in order for us to build in this customized behavior we write the add_attributes function. This is what creates and returns the actual decorator at runtime.
@@JakeCallahan That makes sense, thanks