WEBVTT

00:00.000 --> 00:12.000
So, what I'm going to talk about is the match statement and Python.

00:12.000 --> 00:13.500
Maybe a few words about myself.

00:13.500 --> 00:14.500
I'm Mark Lemberg.

00:14.500 --> 00:21.000
I've been around for lots of time, so.

00:21.000 --> 00:25.000
I've done Python for many, many years.

00:25.000 --> 00:27.000
I'm a code developer.

00:27.000 --> 00:36.000
And if you're working with Unicode, if you're working with a DBAPI or the platform module, these things are basically where I helped.

00:36.000 --> 00:41.000
I also founded a user group in this regard, that's where I come from.

00:41.000 --> 00:46.000
And I was a chair of the European Society for a number of years.

00:46.000 --> 00:49.000
I was a director of the PSF for a number of years.

00:49.000 --> 00:52.000
So, I've been around a while, and done lots of things.

00:52.000 --> 00:54.000
But that's not what I'm going to talk about today.

00:54.000 --> 00:56.000
I'm going to talk about the match statement today.

00:56.000 --> 01:01.000
How many people of you know what the match statement actually is?

01:01.000 --> 01:03.000
Good number.

01:03.000 --> 01:07.000
How many of you have actually used the match statement?

01:07.000 --> 01:09.000
So, not that many.

01:09.000 --> 01:10.000
That's interesting.

01:10.000 --> 01:16.000
So, what I'm going to talk about is a bit more advanced stuff in using the match statement.

01:16.000 --> 01:20.000
And we're going to do a quick recap of how the match statement works.

01:20.000 --> 01:24.000
So, this is the match statement.

01:24.000 --> 01:27.000
And there are lots of things in here happening.

01:27.000 --> 01:32.000
And on the next slide, I'm going to show a number of things that you have to be aware of.

01:32.000 --> 01:38.000
If you look at this slide, you'll immediately see that using the match statement is not necessarily trivial.

01:38.000 --> 01:41.000
So, there are lots of things that you have to be aware of.

01:41.000 --> 01:47.000
And lots of terms that you have to know about in order to actually use it properly.

01:47.000 --> 01:50.000
So, the main thing is that you want to match something.

01:50.000 --> 01:55.000
So, you put the match statement, the object that you want to match at the top.

01:55.000 --> 01:57.000
So, match object, that's your match object.

01:57.000 --> 02:00.000
Then you have lots of case statements over here.

02:00.000 --> 02:02.000
Let me see what it works.

02:02.000 --> 02:05.000
Over here, you have the case statements.

02:05.000 --> 02:10.000
And the case statements, they basically tell Python what to match on.

02:10.000 --> 02:13.000
And in each case statement, you have a type pattern.

02:14.000 --> 02:18.000
Or you have an instant or a sequence or a mapping or a y-code down here.

02:18.000 --> 02:27.000
So, you basically try to identify the particular object that or object case that you want to handle.

02:27.000 --> 02:31.000
And then once Python has actually found that this is a match.

02:31.000 --> 02:33.000
Let's say the object is a list.

02:33.000 --> 02:38.000
For example, then Python will put the object into this.

02:38.000 --> 02:41.000
The match object into this variable here.

02:41.000 --> 02:44.000
And this is called a capturing variable.

02:44.000 --> 02:47.000
There are two ways to use these capturing variables.

02:47.000 --> 02:49.000
One is the explicit way where you say as.

02:49.000 --> 02:52.000
And then the name of the capturing variable.

02:52.000 --> 02:56.000
Another way to do it is, for example, down here in the mapping.

02:56.000 --> 03:01.000
What happens here is if you have a mapping that has a name entry in it.

03:01.000 --> 03:08.000
Then the value of that particular entry in that mapping will get stored into this capturing variable.

03:08.000 --> 03:11.000
Or name in that case or value in this case.

03:11.000 --> 03:15.000
Or in this case, this is a special case where basically you,

03:15.000 --> 03:21.000
you can put everything that has not been matched in your particular pattern.

03:21.000 --> 03:24.000
And you can then make use of that.

03:24.000 --> 03:30.000
There's a special value that you typically put at the very bottom of your match statement,

03:30.000 --> 03:33.000
which is like a y-card.

03:33.000 --> 03:35.000
If you look at the documentation in Python,

03:35.000 --> 03:38.000
typically what gets uses the underscore.

03:38.000 --> 03:42.000
But I find the underscore not that necessarily helpful when reading the code,

03:42.000 --> 03:44.000
because you see an underscore.

03:44.000 --> 03:45.000
You don't know what it means.

03:45.000 --> 03:48.000
Can mean many different things in Python, actually.

03:48.000 --> 03:52.000
So what I typically do is I use a variable, like for example,

03:52.000 --> 03:55.000
unknown or maybe like, you know, every situation or whatever.

03:55.000 --> 04:02.000
And then I'll just output some text here to show the user that something went wrong.

04:02.000 --> 04:06.000
So there are two more important things are actually three.

04:06.000 --> 04:09.000
One is very important one is the instance pattern.

04:09.000 --> 04:14.000
So what you can do is you can actually match on certain types of classes,

04:14.000 --> 04:17.000
including attributes on those classes.

04:17.000 --> 04:19.000
So that's the instance pattern.

04:19.000 --> 04:22.000
The sequence pattern looks like a Python list.

04:22.000 --> 04:26.000
It actually matches a lot more than just a Python list.

04:26.000 --> 04:30.000
It matches anything that has the sequence protocol in Python.

04:30.000 --> 04:32.000
And same with the mapping.

04:32.000 --> 04:34.000
The mapping here looks like the Python dictionary,

04:34.000 --> 04:40.000
but it will actually match anything that implements the mapping protocol.

04:40.000 --> 04:42.000
So that was the short recap.

04:42.000 --> 04:44.000
I'm not going to go into much detail here.

04:44.000 --> 04:46.000
The reason why I'm giving these talks.

04:46.000 --> 04:50.000
I gave it talk about the basic match statement last year at Frostham.

04:50.000 --> 04:52.000
And this is the more advanced one.

04:52.000 --> 04:56.000
The reason I'm giving these talks is the match statement is not that well known yet.

04:56.000 --> 05:00.000
And what's worse, it's not to use that much.

05:00.000 --> 05:04.000
And it's really excellent new tool that we have in Python.

05:04.000 --> 05:10.000
And we've had it since Python 3.10, which got released in October 21.

05:10.000 --> 05:14.000
So that's three and a half years ago.

05:14.000 --> 05:18.000
And if you look at the statistics here, the statistics are not that new,

05:18.000 --> 05:22.000
because the website I took it off, they haven't updated the statistics.

05:22.000 --> 05:24.000
So it's from July 2023.

05:24.000 --> 05:30.000
But as you can see here, the match statement is only used in about .58%

05:30.000 --> 05:32.000
of all the packages on Python.

05:32.000 --> 05:36.000
So not that much, and I'm going to, you know,

05:36.000 --> 05:40.000
I want to basically increase that usage a bit by giving these talks.

05:40.000 --> 05:44.000
One of the reasons why it's probably not being used that much is because

05:44.000 --> 05:46.000
the documentation is a bit lacking.

05:46.000 --> 05:50.000
So essentially what you have is you have these three peps.

05:50.000 --> 05:58.000
That were posted in order to basically get the match statement into Python.

05:58.000 --> 06:04.000
The first one is just the motivation, why it's good, why you, why it should be used,

06:04.000 --> 06:08.000
discusses the syntax and everything, but it's very technical.

06:08.000 --> 06:12.000
Same with the last one, the 6341.

06:12.000 --> 06:14.000
That's actually a specification.

06:14.000 --> 06:18.000
So if you read that one, that goes into all the details that you have

06:18.000 --> 06:20.000
in with the match statements.

06:20.000 --> 06:22.000
If you want to start learning about the match statement,

06:22.000 --> 06:26.000
the best way to do that is to read the peps 636.

06:26.000 --> 06:28.000
That's a tutorial.

06:28.000 --> 06:32.000
And by reading that, you can actually, you know, try to understand

06:32.000 --> 06:34.000
how the match statement works.

06:34.000 --> 06:36.000
The problem with all of this is that,

06:36.000 --> 06:40.000
normally what happens is you write the peps to get something into Python

06:40.000 --> 06:42.000
and then you write proper documentation.

06:42.000 --> 06:46.000
Well, that last part hasn't happened for the match statement.

06:46.000 --> 06:50.000
So essentially, the match statement documentation that you find

06:50.000 --> 06:54.000
in the regular Python documentation is more or less the same thing

06:54.000 --> 06:56.000
as what you have in the peps.

06:56.000 --> 07:00.000
So, yeah.

07:00.000 --> 07:02.000
Could be improved, let's say.

07:02.000 --> 07:04.000
So patches are welcome, of course.

07:04.000 --> 07:07.000
So some things that I did not have on the other slide,

07:07.000 --> 07:10.000
some more advanced features that you have in the match statement.

07:10.000 --> 07:12.000
I put on this slide.

07:12.000 --> 07:15.000
So the first thing is that you can do or parsing.

07:15.000 --> 07:19.000
So if you let's say you have multiple values that you want to match

07:19.000 --> 07:23.000
and you can use the or operator for that.

07:23.000 --> 07:27.000
You can match optional things and put them somewhere

07:27.000 --> 07:29.000
in capturing variables.

07:29.000 --> 07:33.000
For example, the dot arcs would match anything that's in a list

07:33.000 --> 07:37.000
let's say after the first one and two.

07:37.000 --> 07:40.000
You can use underscores if you want to.

07:40.000 --> 07:42.000
If you're not interested in certain things,

07:42.000 --> 07:45.000
basically these are throw away kind of capturing variables.

07:45.000 --> 07:47.000
And the same thing works with dictionaries.

07:47.000 --> 07:51.000
I already mentioned the more.

07:51.000 --> 07:57.000
Basically capturing variable to capture anything that is not in that pattern.

07:57.000 --> 08:00.000
Very important is the instance parsing.

08:00.000 --> 08:02.000
We're going to go into more detail on that one.

08:02.000 --> 08:06.000
And then sometimes what you want to do is you want to put local variables

08:06.000 --> 08:07.000
in your patterns as well.

08:07.000 --> 08:11.000
And the way that works is, well, let's say it's a bit of a hack.

08:11.000 --> 08:17.000
So normally what happens is whenever Python finds a variable name in your pattern,

08:17.000 --> 08:22.000
it will basically interpret that as a capturing variable.

08:22.000 --> 08:28.000
Now in order to make Python aware that you actually want to reference a local variable in your context,

08:28.000 --> 08:32.000
you have to put a dot into the variable reference somewhere.

08:32.000 --> 08:37.000
And a typical way to do that is to basically just maybe use a class or data class or whatever

08:37.000 --> 08:39.000
and then you put your stuff in there.

08:39.000 --> 08:43.000
And then inside the pattern, you then write for example,

08:43.000 --> 08:45.000
ParamStot and then variable name.

08:45.000 --> 08:47.000
There are lots more things that you can do.

08:47.000 --> 08:49.000
You should have a look at the Python detail.

08:49.000 --> 08:53.000
Yeah, talk from Raymond Hedinger in 2022.

08:53.000 --> 08:59.000
For more things that you can do with the more advanced stuff.

08:59.000 --> 09:03.000
So I'm going to show a number of examples here and go into the details.

09:03.000 --> 09:05.000
So I'm going to start with Jason to examples there.

09:05.000 --> 09:09.000
Then have a look at XML, which we all love.

09:09.000 --> 09:15.000
And then I have a really complicated example using the AST, the Python AST.

09:15.000 --> 09:19.000
So let's start with a simple one.

09:19.000 --> 09:23.000
This is basically just tabular data that you put into Jason.

09:23.000 --> 09:26.000
And what you see here is you have to schema up there.

09:26.000 --> 09:30.000
So basically you have entry, dictionaries, which have a price entry,

09:30.000 --> 09:34.000
a name entry and then the price is a number and the name is a string.

09:34.000 --> 09:38.000
And then these are some examples of things that you can see.

09:38.000 --> 09:40.000
In the data, sometimes you get extra data.

09:40.000 --> 09:43.000
For example, in data three, you have this color entry in there.

09:43.000 --> 09:45.000
And you have to deal with these things.

09:45.000 --> 09:49.000
And what you typically have is you have a list of these dictionaries.

09:49.000 --> 09:52.000
And then you try to process them.

09:52.000 --> 09:55.000
So how would you do that with the match statement?

09:55.000 --> 09:59.000
As I just mentioned, there's a QR code up there.

09:59.000 --> 10:01.000
In case you cannot read this, you can download the slides.

10:01.000 --> 10:05.000
And then you have a better way of reading these things.

10:05.000 --> 10:08.000
I did want to put lots of code on the slides.

10:08.000 --> 10:11.000
So I have to make the font size a bit smaller.

10:11.000 --> 10:13.000
What you do here is it's very typical.

10:13.000 --> 10:15.000
You start with a single record.

10:15.000 --> 10:18.000
So you basically match one of these instances.

10:18.000 --> 10:21.000
Then you want to make sure that it's actually a dictionary.

10:21.000 --> 10:22.000
So you have a case dict.

10:22.000 --> 10:26.000
And then you work on that particular dictionary.

10:26.000 --> 10:29.000
If it's not a dict, then it goes down here and says wrong value.

10:29.000 --> 10:32.000
And then you can do some error processing here.

10:32.000 --> 10:35.000
And then what you do is you have another match statement.

10:35.000 --> 10:37.000
And you look into that particular dictionary.

10:37.000 --> 10:39.000
And you parse it in here.

10:39.000 --> 10:45.000
And as you can see here, you can go in and say, OK, the name has to be a string value.

10:45.000 --> 10:48.000
And I'm going to store it in the capturing variable name.

10:48.000 --> 10:51.000
And the price has to be an int or a float.

10:51.000 --> 10:54.000
And you use the ore pad on here.

10:54.000 --> 10:58.000
You don't, well, what you do is here is you implicitly

10:58.000 --> 11:01.000
store it in the capturing variable price in both cases.

11:01.000 --> 11:05.000
And then if you have anything extra, then you can do some error processing here,

11:05.000 --> 11:07.000
like what I mentioned with the color entry.

11:07.000 --> 11:11.000
And then in normal cases, you process your data down here.

11:11.000 --> 11:14.000
And again, if you have anything that does not match these things.

11:14.000 --> 11:16.000
Let's say the name is not a string.

11:16.000 --> 11:17.000
Maybe an integer.

11:17.000 --> 11:20.000
Then you would go down here and see wrong values.

11:20.000 --> 11:25.000
So very straightforward, very readable.

11:26.000 --> 11:28.000
And easy to understand.

11:28.000 --> 11:31.000
Now, of course, if you have multiple of these records,

11:31.000 --> 11:33.000
then you would put them into a list.

11:33.000 --> 11:36.000
And then again, you do the same thing.

11:36.000 --> 11:41.000
What I typically do is I put the actual, I split the parsing in multiple functions

11:41.000 --> 11:45.000
or methods so that the code becomes more readable.

11:45.000 --> 11:48.000
So what I do here is I explicitly say, OK, this has to be a list.

11:48.000 --> 11:50.000
If it's not a list, something is wrong.

11:50.000 --> 11:51.000
And I go here.

11:51.000 --> 11:55.000
If it is a list, then I basically look at all the different dictionaries I have in there

11:55.000 --> 11:59.000
and then call the other function to do the parsing.

11:59.000 --> 12:02.000
So that was very easy.

12:02.000 --> 12:07.000
Now, a bit more complex in case of if you want to use geo JSON.

12:07.000 --> 12:10.000
How many of you know what geo JSON is?

12:10.000 --> 12:11.000
Yeah, a few.

12:11.000 --> 12:16.000
So basically it's about storing a spatial data in JSON.

12:16.000 --> 12:18.000
It's a standard format.

12:18.000 --> 12:22.000
And the example I took here is directly from the website.

12:22.000 --> 12:30.000
This is referencing a tiny island down here in Philippines called the denogat islands.

12:30.000 --> 12:37.000
And basically what it does is it's just that there is a point that you want to reference.

12:37.000 --> 12:43.000
It gives you the coordinates and then it assigns a name as a property to that particular point.

12:43.000 --> 12:48.000
So this is what you want to parse and there are different geo JSON types in here.

12:48.000 --> 12:54.000
So you have not only point, but also feature and feature collection and lots of other stuff.

12:54.000 --> 12:59.000
And you want to make sure that when you parse these things that only these types get used.

12:59.000 --> 13:02.000
And so that you don't get any wrong data.

13:02.000 --> 13:04.000
So again, you go in here.

13:04.000 --> 13:08.000
You take one of these instances that you have.

13:08.000 --> 13:12.000
And then you go in here into your first case.

13:12.000 --> 13:19.000
You analyze first you analyze just a type part of that particular case.

13:19.000 --> 13:21.000
Sorry, the particular instance.

13:21.000 --> 13:24.000
And then you put the everything else that you've matched into other members.

13:24.000 --> 13:26.000
Then you can look into that later on.

13:26.000 --> 13:34.000
So the first thing that you do is you make sure that only the geo JSON types that you have defined in the standard actually being used.

13:34.000 --> 13:37.000
Otherwise you store an exception or print something.

13:37.000 --> 13:42.000
And then you go into the other members and analyze all the other members that you have in here.

13:42.000 --> 13:46.000
Now what's happening here is that this is actually this is nested data, right?

13:46.000 --> 13:49.000
So it's not tabular as in the first example.

13:49.000 --> 14:00.000
And so you can do you can have a four loop in here and then for the nesting you typically use another match statement that you have here.

14:00.000 --> 14:06.000
And then you get the different entries that you can have as other members and again you do some error processing down here.

14:06.000 --> 14:10.000
I'm not showing any processing of these things.

14:10.000 --> 14:14.000
I just want to show that you can extract the data and easily then use it.

14:14.000 --> 14:19.000
What's very nice is that because you have these capturing variables you can directly tap into the data.

14:19.000 --> 14:23.000
So you can do both validation of the data.

14:23.000 --> 14:25.000
So I'm making sure that it's a proper format.

14:25.000 --> 14:29.000
And you can immediately start processing everything.

14:30.000 --> 14:34.000
So I have eight minutes and forty left, which is not a lot.

14:34.000 --> 14:37.000
So I'm going to basically rush a bit.

14:37.000 --> 14:41.000
So the next is the XML data we all love, right?

14:41.000 --> 14:44.000
So this is basically taking from the Python documentation.

14:44.000 --> 14:45.000
This is an excellent.

14:45.000 --> 14:57.000
These are XML records that are again a bit more complex because you're storing neighbors of countries in here and you store a rank and the GDPC.

14:58.000 --> 15:01.000
And so you want to parse this.

15:01.000 --> 15:04.000
The way you do it is you of course use elementary for these things.

15:04.000 --> 15:10.000
Elementary has an instance type called element and this is what we're using here.

15:10.000 --> 15:18.000
So we basically parse for the element and then we make sure that the element that we first parse is the country element.

15:18.000 --> 15:23.000
We extract the attributes on that particular element into the variable name.

15:23.000 --> 15:27.000
And we store the whole thing as country as the country.

15:27.000 --> 15:29.000
They're capturing variable.

15:29.000 --> 15:34.000
And then we go into country and look at the different entries that we find in the XML.

15:34.000 --> 15:38.000
So you have the example over here so you can compare that.

15:38.000 --> 15:42.000
So the first things are very easy because they can just occur once.

15:42.000 --> 15:49.000
So you basically go through these things and just make sure that you get the proper values, the proper types.

15:50.000 --> 15:53.000
And then you go down here and to neighbors because you can have multiple neighbors.

15:53.000 --> 15:58.000
You basically parse every neighbor entry that you have in here and you put them into a dictionary.

15:58.000 --> 16:08.000
And then later on you combine everything into a proper dictionary that you can use in processing and then you go on with the processing.

16:08.000 --> 16:18.000
So again, I think this is fairly straightforward, especially if you what you normally do it with when you parse XML you go into some kind of you have a parser object.

16:18.000 --> 16:22.000
And you have handlers on that and you use that kind of approach.

16:22.000 --> 16:32.000
Or you have long if if if if elephant and so on kind of patterns which are not easy to read, not easy to write.

16:32.000 --> 16:39.000
And I think even though this is a bit you know compressed on this slide, I think this is actually quite readable.

16:39.000 --> 16:43.000
If you look at that code, you can actually understand what it's doing.

16:43.000 --> 16:52.000
I did leave out some details that you would normally put in here, for example, you would make sure that you only get one rank entry in there and one year.

16:52.000 --> 16:57.000
But it doesn't want to make it too complex, but that's certainly all possible to do.

16:57.000 --> 17:04.000
Now let's get asked last example, let's get to the AST. How many of you have worked with the Python ASTs?

17:04.000 --> 17:13.000
That's interesting. So what you see there on the right and very tiny font is part of an AST.

17:13.000 --> 17:19.000
The AST I'm showing here is actually the AST of this function, the example function on the left.

17:19.000 --> 17:30.000
As you can see, it's highly nested. It looks a bit, for example, you have a linear structure here, you have if L of L of L is right.

17:30.000 --> 17:48.000
But if you look at the AST, what happens here is actually a nested structure. So the first is a top note and then you basically have in that if you have other instances, I can't really see that from here.

17:48.000 --> 17:56.000
It doesn't show. So it's probably in this lots more down here. So this is basically parsing just the first if part.

17:56.000 --> 18:12.000
And then you have the body of that if statement, which is the print over here. And then further down below, you have two parts. You always have with the if AST, you always have the matching part and then you have the L's part.

18:12.000 --> 18:18.000
So everything that you see here on the L of would then go into the L's part.

18:18.000 --> 18:29.000
If you think about the tree that gets generated, it's actually a deeply nested tree for the if L of it's not a list as you might think when looking at these things.

18:29.000 --> 18:42.000
So what's the idea here I want to show very quickly. Obviously you want to refactor this if L of chain into something that uses the match statement automatically programatically.

18:43.000 --> 18:49.000
And this is how it works. So it's a bit more involved. So what I'm going to do is I'm going to first.

18:49.000 --> 18:54.000
This is the main entry point here, the if match refactor function.

18:54.000 --> 19:03.000
What it does is it basically goes into AST, finds the function definitions, finds the, you know, the some variable names in here.

19:03.000 --> 19:13.000
And then it goes into function refactor, which is over here, which then tries to find in that function definition, the if L of L's chains in here.

19:13.000 --> 19:20.000
So the way it works is you go in here, you check all the notes, you just interested in the if notes that you have in here.

19:20.000 --> 19:26.000
And then if you find an if note, you go into another function scan if, which is on the next slide.

19:26.000 --> 19:35.000
You parse that and then you check the return values and then you replace the the note, not here you look.

19:35.000 --> 19:43.000
You you create and you note, you want to replace the if statement with the match statement, that's what you do here.

19:43.000 --> 19:53.000
And then you replace that note in the function body and return it and then you get the modified function.

19:53.000 --> 20:01.000
So this is scan if, again, this is the what I mentioned already, the trick to do local variables.

20:01.000 --> 20:05.000
So I just use an empty parent's class for that.

20:05.000 --> 20:17.000
And then I put the variable name in here because I need that and then I go into the into deeper into the the chain of the if statement.

20:17.000 --> 20:22.000
So I'm going to look at the condition that you have in the if statement.

20:22.000 --> 20:35.000
I'm going to look for a first case, which is calling is instance to find at the type that you normally use in these if chains when you do something like a matching pattern and then I'm going to go into.

20:35.000 --> 20:43.000
Another case down here, which is you call these instance plus you have an extra condition that you want to handle.

20:43.000 --> 20:54.000
So I'm going to have to skip over this a bit unfortunately the code is all available on the on the in the slides that you you can download from the QR code up there.

20:54.000 --> 21:03.000
What's happening here is basically you you go in here and then you you find all these cases that you have in here.

21:03.000 --> 21:13.000
And then you recursively continue because like I said it's it's deeply nested structure you recursively go into the other cases that you have in your chain.

21:13.000 --> 21:23.000
And basically apply the restructuring in in all the different cases that you find that you can actually handle everything else that you cannot handle is not being touched.

21:23.000 --> 21:28.000
So this will only look at these if chains.

21:28.000 --> 21:46.000
And then what you of course want to do is you want to then replace that if statement with the match statement the way you do that is you take all your cases that you've collected here and then you create new nodes in the AST by using match class and then and the match case here.

21:46.000 --> 21:58.000
And then you put all the variables in here this is what Python needs in order to represent a not statement in the AST and then you append all the different cases and you return that.

21:58.000 --> 22:11.000
Down here and what you get is code that actually goes from left to right automatically and it doesn't touch anything else if you have something if you have code before the if or after the if.

22:11.000 --> 22:14.000
It will just remain unchanged.

22:14.000 --> 22:21.000
It will also only work on things that it actually recognizes so everything else that is not recognized.

22:21.000 --> 22:27.000
It won't touch you could put extra code in there that may be maybe it's just a warning that something didn't work.

22:27.000 --> 22:30.000
But that's pretty much it.

22:30.000 --> 22:36.000
Right so what about performance in the last few seconds I have I'm just kind of very quickly show this.

22:36.000 --> 22:46.000
And these are different cases that I've looked at as you can see them the match variable variant is still a bit slower than the if variant.

22:46.000 --> 22:50.000
Except for one case where you have over here you have a.

22:50.000 --> 22:56.000
Basically a list of integers that you want to match then the match statement is actually faster.

22:56.000 --> 23:05.000
There's a strange case over here with the inline capturing variables there's something wrong there and in Python obviously because if you inline something else.

23:06.000 --> 23:11.000
It's just very very slow compared to the generic case where use the ass.

23:11.000 --> 23:14.000
It's probably a box somewhere.

23:14.000 --> 23:19.000
Thing is this is still the first implementation of the match statement.

23:19.000 --> 23:28.000
So there's still you know lots of low hanging food there could be lots of ways of improving things for example even compiling stuff maybe into byte code.

23:29.000 --> 23:32.000
To to make things run faster.

23:32.000 --> 23:42.000
But for now it's the the most important thing about the match statement is that you can actually use it to get your code more readable moment moment attainable.

23:42.000 --> 23:54.000
And as always in Python you know we start with something that is basic and then over time we improve the performance so after let's say if you're really system the performance will be good as well.

23:54.000 --> 23:57.000
And so there shouldn't be any issues there.

23:58.000 --> 24:05.000
So basically conclusion match isn't fast yet but of course we can make it so.

24:05.000 --> 24:16.000
What's very good is if you compare the left side to the middle box there with the match statement this is a lot more readable right I guess you would agree and so.

24:16.000 --> 24:20.000
I would recommend starting to use it.

24:20.000 --> 24:24.000
I mean take away never stop learning August right and things.

24:24.000 --> 24:25.000
Thank you.

24:33.000 --> 24:40.000
So I think we don't have time for questions if you have any questions you can just come to me approach me and then we can.

24:40.000 --> 24:41.000
Hashtag.

24:41.000 --> 24:42.000
Thank you.

24:50.000 --> 24:52.000
Thank you.

