A better demo of why wrap is important would be to modify expensive_function to raise an error and see what you get. For example, raise ValueError('check stack trace')
I didn't know this was a problem for Python, so thanks for the warning. I am curious though both how @wraps is implemented as well as whether standard library decorators use it. Maybe do a video on that?
It's also very useful so that you still get autocomplete functionality for your wrapped functions; otherwise, information on the names and types of arguments is lost.
I did not know this and apperently some devolpers also don't know this - I just tested with the function decorator from latexify liberary and it overwrites the doc string. Hey could you write a wrapper function that properily wraps 3rd party decorators below it?
I couldn't understand why we opened a function called wrapper in the function. Why doesn't it work if we write it directly into Get Time without opening a function called wrapper (I translated it using Google Translate, it may have been translated poorly)
@kiraleskirales I know the decorative thing too. And what I'm asking is why we write it inside the Function(): wrapper() .... Return wrapper Instead of writing it directly inside the wrapper, why not write it inside the Function? Why is there a need to create a wrapper?
@bartuustaoglu4167 Because a decorator is a function. When you do @decorator above a function "f" it's like doing decorator(f). Which is why attribute like name are change without @wrap. To be more specific when you run a script everey @decorator are execute, you can easely see that by printing a value before the wrapper inside the decorator. Another important point is that you need a third function that will output a decorator when call in order to allow parameter inside you decorator like "@get_time(round=2)" instead of "@get_time".
From a quick Google search, this is fully automatic and neither of us have the option to manually disable it. It might work if you change all of your UA-cam to English,
Nein, bitte lass alles so wie es ist. Ich möchte gerne das jeder gleichermaßen den Schwachsinn von Google und UA-cam ertragen muß und niemand sich freikaufen kann. Gleiches Recht für alle! Muß gelten.
Very useful for logging with an exception catching wrapper. Thank you great video!
Thank you! Your hints are a real treasure!
A better demo of why wrap is important would be to modify expensive_function to raise an error and see what you get. For example, raise ValueError('check stack trace')
I just tried this, but there was no difference in Traceback🤔(Python 3.12)
I didn't know this was a problem for Python, so thanks for the warning. I am curious though both how @wraps is implemented as well as whether standard library decorators use it. Maybe do a video on that?
You create cool short videos about Python. You also create very good courses, thanks for your job.
Learned something new today! 👍🏼 Thanks
Happy New Year mr Indently!
Happy new year!
That's very useful to make things easier
Thanks for this tip !
Great stuff nicely explained
It's also very useful so that you still get autocomplete functionality for your wrapped functions; otherwise, information on the names and types of arguments is lost.
Thank you 😊
Very useful!
I did not know this and apperently some devolpers also don't know this - I just tested with the function decorator from latexify liberary and it overwrites the doc string. Hey could you write a wrapper function that properily wraps 3rd party decorators below it?
Very usefull
why are you prefering ' instead of "?
Less screen clutter, and the odds of me using double quotes inside strings are usually much higher than single quotes.
The wrapt module has much better decorators for these things
what is this green line? is it a new update? is it a plugin?
It PyCharm Git plugin visualizing file change
❤
I couldn't understand why we opened a function called wrapper in the function. Why doesn't it work if we write it directly into Get Time without opening a function called wrapper (I translated it using Google Translate, it may have been translated poorly)
The decorator pattern is very useful. Firstly, it can be reused, and secondly it conceptually separates the computation and the time performance.
@kiraleskirales I know the decorative thing too. And what I'm asking is why we write it inside the
Function():
wrapper()
....
Return wrapper
Instead of writing it directly inside the wrapper, why not write it inside the Function? Why is there a need to create a wrapper?
@bartuustaoglu4167 Because a decorator is a function. When you do @decorator above a function "f" it's like doing decorator(f). Which is why attribute like name are change without @wrap. To be more specific when you run a script everey @decorator are execute, you can easely see that by printing a value before the wrapper inside the decorator. Another important point is that you need a third function that will output a decorator when call in order to allow parameter inside you decorator like "@get_time(round=2)" instead of "@get_time".
Decorator for decorator
-> metadecorator 🤔
Chained decorators ?
What are the "new*" lines above each function? Looks like they were autogenerated and not part of the script itself; a PyCharm thing perhaps?
It from PyCharm Git plugin
@@kerty- Ah, thanks
@@kerty- I was wondering about that.
Lol,no async support
Please disable the automatic dubbing. I can see the benefit for many users but I'm fluent in English and I don't want it in my local language.
I don't have that option in the settings. Did you check your UA-cam settings?
From a quick Google search, this is fully automatic and neither of us have the option to manually disable it.
It might work if you change all of your UA-cam to English,
Nein, bitte lass alles so wie es ist. Ich möchte gerne das jeder gleichermaßen den Schwachsinn von Google und UA-cam ertragen muß und niemand sich freikaufen kann. Gleiches Recht für alle! Muß gelten.
In the video settings you should be able to select the audio track. I haven't checked my computer but it works on my phone at least
@@eaglegosuperskarmor sure, I can do this manually. But it doesn't stick, the next video will be auto-dubbed again.