1
00:00:01,630 --> 00:00:03,010
Hi guys, and welcome back.

2
00:00:03,010 --> 00:00:04,240
In this video, we're going to learn

3
00:00:04,240 --> 00:00:06,910
about decorating functions with parameters.

4
00:00:06,910 --> 00:00:08,370
So, let's take a look at our example,

5
00:00:08,370 --> 00:00:10,830
and do a little bit more with it.

6
00:00:10,830 --> 00:00:13,700
Here we've got our make secure decorator

7
00:00:13,700 --> 00:00:16,430
and our get admin password function.

8
00:00:16,430 --> 00:00:18,130
If instead of get admin password

9
00:00:18,130 --> 00:00:20,470
we wanted to change this to get password

10
00:00:20,470 --> 00:00:23,590
and take in a panel decorator and then do something like

11
00:00:23,590 --> 00:00:27,300
if panel is admin then return one, two, three, four

12
00:00:27,300 --> 00:00:30,200
otherwise if panel is billing

13
00:00:30,200 --> 00:00:33,660
then return super secure password.

14
00:00:33,660 --> 00:00:35,070
Something like that.

15
00:00:35,070 --> 00:00:37,940
Now, of course, when you call the function

16
00:00:37,940 --> 00:00:41,680
you're going to have to pass an A panel, such as billing.

17
00:00:41,680 --> 00:00:46,680
But this function actually won't take in the argument

18
00:00:46,730 --> 00:00:51,730
because our function here, calls the original function

19
00:00:51,780 --> 00:00:53,520
without the argument.

20
00:00:53,520 --> 00:00:56,550
So here's what's gonna happen when you call get password.

21
00:00:56,550 --> 00:01:01,460
Remember, get password is replaced by secure function.

22
00:01:01,460 --> 00:01:02,630
So, secure function at the moment

23
00:01:02,630 --> 00:01:04,500
does not have any parameters

24
00:01:04,500 --> 00:01:07,910
so you won't be able to pass billing to it.

25
00:01:07,910 --> 00:01:11,620
In addition, when you call the original function

26
00:01:11,620 --> 00:01:13,380
no argument is passed either,

27
00:01:13,380 --> 00:01:16,240
so even if this function took the argument in,

28
00:01:16,240 --> 00:01:17,550
it wouldn't be passed in then.

29
00:01:17,550 --> 00:01:18,750
So obviously we have to fix that.

30
00:01:18,750 --> 00:01:22,400
We have to put the panel in there and the panel in there.

31
00:01:22,400 --> 00:01:25,660
Then what happens is billing gets passed to secure function

32
00:01:25,660 --> 00:01:27,410
then it gets passed to the original function

33
00:01:27,410 --> 00:01:30,580
which is get password, and then this will work.

34
00:01:30,580 --> 00:01:32,160
However, this is not good

35
00:01:32,160 --> 00:01:36,430
because we have coupled our make secure decorator

36
00:01:36,430 --> 00:01:37,570
to this function.

37
00:01:37,570 --> 00:01:40,080
That means that we can't use it on other functions

38
00:01:40,080 --> 00:01:42,850
that take in different arguments.

39
00:01:42,850 --> 00:01:45,140
So instead, what you usually do with decorators,

40
00:01:45,140 --> 00:01:47,860
is you make them take unlimited numbers

41
00:01:47,860 --> 00:01:49,500
of arguments and keyword arguments

42
00:01:49,500 --> 00:01:51,580
so you can cater for everything.

43
00:01:51,580 --> 00:01:53,310
Then once you do that, as you may know already,

44
00:01:53,310 --> 00:01:56,230
is star args and star, star kwargs.

45
00:01:56,230 --> 00:01:58,670
And then you just pass them on as well

46
00:01:58,670 --> 00:02:01,200
to the original function.

47
00:02:01,200 --> 00:02:04,960
So that will make it work and also it won't limit you

48
00:02:04,960 --> 00:02:07,010
to using it with only this function.

49
00:02:07,010 --> 00:02:08,690
You can use it with any other function.

50
00:02:08,690 --> 00:02:11,810
This get password here must still be called

51
00:02:11,810 --> 00:02:15,420
with the correct argument for the original function.

52
00:02:15,420 --> 00:02:17,510
But this one here doesn't care

53
00:02:17,510 --> 00:02:20,170
what arguments are passed in.

54
00:02:20,170 --> 00:02:21,390
That's everything for this video.

55
00:02:21,390 --> 00:02:22,850
Thank you for joining me in this one,

56
00:02:22,850 --> 00:02:24,500
and I'll see you in the next one.

