Python 3.11: A Guided Tour Through Code Transcripts
Chapter: Error Messages
Lecture: What's The Problem with Error Reporting Now?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's see the problem they're trying to solve here with this Pep.
0:03 And this new feature. We've got this function a little bit contrived but not entirely unreasonable called Func 1,
0:10 it takes five arguments. We could use python type ends to make a little clear what the point of these
0:17 are. But the first one is a dictionary. The next four are keys that we want to use to navigate some kind of hierarchy of data within that dictionary.
0:28 So we go to a the dictionary we say get b why b is the key. And then we say from that 'b' inside. That's part of the dictionary.
0:38 We should have something called C. From that. We should have something called D and then something called E
0:42 And then that's gonna be a string. And so we want to remove all the extra white space and
0:47 make it uppercase. No problem. Right. Should work when we run this code write a function like this we'll say V1 V2 V3, V4 V5.
0:57 These are the different variables that we're passing in. Let's say this works most of the time.
1:02 But sometimes rarely in production doesn't work. And we're gonna log what happens.
1:09 Well, we're gonna get a trace back and it'll say something like this. Well, there's a problem on this line. The one line of that function a.get(b).
1:18 get(c) and so on. What is the error errors? None type object has no attribute yet. Oh boy. Well there's a lot of things that could be going wrong here.
1:29 Let's think about this. It could be that A. Was none. In which case when we tried to call get 'b' on it.
1:36 We got this error but let's suppose A. Is fine or maybe the return value of get(b) itself is none. And then when we tried to call get(c).
1:46 On it we got this error. Same thing for the return value of get(c) remember this is a dictionary when
1:52 you call get if you the key does not exist it's just gonna return none.
1:58 If we had square brackets it would be a key here but here it's gonna return none. So maybe that's what happened for when we tried to call get(d).
2:04 Or get(e). It's not the strip. So the return value of get(e) is fine or never made it
2:10 that far. And similarly for strip and upper. So it's one of the first four but we don't know which one now do we? This is python 3.10 or earlier.
2:20 However if we write exactly the same code literally take the same source and just run it in Python 3.11
2:28 notice the little carrots or the hat symbols here they go from the beginning all the way up to get(d)
2:35 What does that tell us? Well it tells us right there that call to get(d).
2:40 Crashed. That's what caused this exception. So that means the return value of get(c). Must have been none. Such that when we called get(d).
2:51 On it it crashed awesome. We know right away, there's a whole bunch of these types of improvements from this pep. We gonna explore them now.


Talk Python's Mastodon Michael Kennedy's Mastodon