SIMPLIFY your code with decorators (+ typing)

  Рет қаралды 3,465

Carberra

Carberra

Күн бұрын

Decorators are amazing in Python, but have a habit of tripping a lot of people up! This video will cover the basics of creating simple and parametrised decorators (also known as decorator factories), as well as how to type them.
00:00 - Intro
00:49 - Creating a simple decorator
05:59 - Typehinting simple decorators
08:25 - Creating a parametrised decorator (decorator factory)
12:18 - Typehinting parametrised decorators
13:31 - Outro
-
If you want to see more of me, join my Discord server!
/ discord
I get a lot of people asking, so here's my setup!
• Visual Studio Code: • My Visual Studio Code ...
• Terminal: • Make your terminal loo...
-
If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.
#python #coding #howto

Пікірлер: 15
@ThijsFranck
@ThijsFranck 28 күн бұрын
Thanks for highlighting ParamSpec, I've been looking for a way to define generic function parameters in Python forever!
@jake115577
@jake115577 27 күн бұрын
I never would have come up with the UNITS trick! Great video sir.
@pythonwithjames
@pythonwithjames 26 күн бұрын
This is great, really loved the explanation!
@Carberra
@Carberra 25 күн бұрын
Thanks man! I tried to be very thorough about it cos I get asked about decorators quote a bit, and see quite a lot of confusion about them elsewhere too.
@MaxShapira2real
@MaxShapira2real 23 күн бұрын
Love it! Awesome job as always. Could you share the link to the video that shows how type-parameterized decorators were cleaned up and made less messy?
@Carberra
@Carberra 21 күн бұрын
Thanks! Soz forgot to link it kzbin.info/www/bejne/lYK7nZWth9Kknas
@yousefsaddeek
@yousefsaddeek 27 күн бұрын
look my local network was off and i was codding python for a little open source drawing app and i am constantly thinking about how to make it simpler and i remember that there is something called decorator in python and i thought it would be nice to use them and i spend few minutes to remember the exact sentax for decorators and i got the most part but what is driving me crazy how dose this video showed up immediately when the internet is back in my feed and since the internet was off I did not even think to use Google search or any kind of app and so you imagine the situation correctly I don't usually look for any python syntax or feature like it's so damn rare ☠️☠️☠️
@Micaeljm
@Micaeljm 27 күн бұрын
Great video! I was hoping you would show how to make a decorator that supports both `@timer` and `@timer("ms")` (with or without arguments) at the end, which is something that I can never remember how to do right.
@Carberra
@Carberra 27 күн бұрын
Glad you enjoyed! And I cover that next week!
@thomaseb97
@thomaseb97 23 күн бұрын
python generally has really bad syntax for functional concepts and such, it's very opinionated on being object oriented and imperative the type hint for a function is really bad, it can get very bloated with the Callable[[T, U], R] especially when nested and lambdas are not implemented well nor are the syntax intuative using TypeAlias from typing is very helpful to help with the bloating of Callable
@duffydan26
@duffydan26 29 күн бұрын
Can you cover meta classes in Python?
@Carberra
@Carberra 29 күн бұрын
Already have! 😄 kzbin.info/www/bejne/hKvdfIeNnsaBbJo
@sto3359
@sto3359 29 күн бұрын
Great tutorial, but the guy has some serious David Koresh vibes going on :(
@Carberra
@Carberra 28 күн бұрын
Wasn't expecting to get compared to a cult leader today I'll be honest.
Python has BIOMETRIC support?!
11:43
Carberra
Рет қаралды 2 М.
Python's contextlib is a HIDDEN GEM
14:55
Carberra
Рет қаралды 9 М.
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 56 МЛН
A pack of chips with a surprise 🤣😍❤️ #demariki
00:14
Demariki
Рет қаралды 50 МЛН
Они убрались очень быстро!
00:40
Аришнев
Рет қаралды 3,6 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:19
CRAZY GREAPA
Рет қаралды 21 МЛН
5 Useful Python Decorators (ft. Carberra)
14:34
Indently
Рет қаралды 88 М.
10 Nooby Mistakes Devs Often Make In Python
24:31
Indently
Рет қаралды 42 М.
5 Cool Python One-Liners
12:23
Indently
Рет қаралды 28 М.
Why It (Mostly) Doesn't Matter How You Code In Rust
22:57
Oliver Jumpertz
Рет қаралды 11 М.
PLEASE Use These 5 Python Decorators
20:12
Tech With Tim
Рет қаралды 97 М.
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 127 М.
5 Tips To Write Better Python Functions
15:59
Indently
Рет қаралды 93 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 136 М.
reverse engineering makes you a better programmer (let’s try it out)
13:12
Low Level Learning
Рет қаралды 148 М.
7 Things I Never Knew About Decorators (Python) Until Recently
14:42
Python With Liu
Рет қаралды 2,4 М.
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 56 МЛН