Transcript #159: Brian's PR is merged, the src will flow
Return to episode page view on github00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
00:05 This is episode 159, recorded November 26, 2019.
00:10 I'm Brian Okken.
00:12 And I'm Michael Kennedy.
00:13 And this episode is brought to you by DigitalOcean.
00:15 Thank you, DigitalOcean. More about them later.
00:17 Michael, what are we talking about right away?
00:19 You know, I'm a big fan of type annotations, and I don't know how I missed this one.
00:24 I can't remember what I was reading.
00:26 It was something we covered on a show recently, and it was talking about the final type annotation.
00:31 I'm like, wait a minute, what? There's a final?
00:33 As in, with object-oriented programming, you know, there's like abstract methods, virtual methods that can be overridden, protected types.
00:42 And some of those things appear in Python, abstract method, for example, but others don't, such as protected or internal.
00:48 Another thing that, until very recently, did not appear in Python is a final type, saying this class cannot be overridden, or this method cannot be overridden in a type hierarchy.
01:01 But now you can.
01:02 Oh, cool.
01:02 And this is actually already in Python 3.8, if I'm reading this right.
01:06 So, this is PEP 591.
01:09 Its status is accepted, and its Python version is 3.8.
01:12 So, I have not actually had a chance to test this out.
01:16 But, yeah, it looks like it is part of it.
01:19 And, you know, because it has to do with typing, of course, Gita Von Rossum is the BDFL delegate, which is kind of interesting.
01:26 He's his own delegate, in a sense.
01:29 But now the steering council is there.
01:31 It's a little bit different.
01:31 But, yeah, so he was part of this, and it adds a final type.
01:35 So, I can say this class cannot be derived from.
01:38 This method should not be overridden.
01:41 And those sound pretty straightforward.
01:42 But as far as I can tell from the use cases they put in the PEP, it's something that is very, very close to a constant value as well.
01:50 What do you mean?
01:51 So, one of the things I can do is I can put an at final decorator on a class, and then if I try to derive from it, the type checker will give me an error saying you cannot inherit from final class, whatever, right?
02:03 Yeah.
02:03 If I put it on a method, and then I try to have a derived class that replaces that method effectively, like implicitly overriding it, I'll get an error.
02:11 It says cannot override final method foo, whatever, right?
02:14 It was first defined.
02:15 But I can also say that there is a variable called rate, which is final, and it equals 3,000.
02:21 And if I try to set it to another value, like rate equals 300, the type checker will give me an error, say cannot assign to a final attribute.
02:29 Okay.
02:29 Or I can go to a class, and I can put that on a field, and if I try to change the field, like if I have a class called base, and it has a default ID, if I say base.defaultID equals something other than what it was initially set to, error cannot override final attribute.
02:44 So the error doesn't say this is a constant value, you cannot do this, but it's like a constant.
02:48 Yeah.
02:49 Okay.
02:50 That's nice.
02:50 It's interesting, right?
02:51 Well, I guess it totally makes sense, because overriding, like deriving from a class or something is kind of similar.
02:59 Certainly changing the name, like the redefining the method in a base class is like replacing the name of it.
03:06 And so the implementation seems to just catch straight up attributes as well, just probably with not much extra work, if any.
03:15 Yeah.
03:15 So this is all the stuff that I'm telling you, this is all type checker magic.
03:19 This is not real, right?
03:22 This is not runtime behavior.
03:24 Right.
03:25 But, you know, I suspect that tooling like PyCharm, for example, if you tried to set that, it would like turn it like yellowish and say, warning, this is a problem here.
03:34 And already, if your editor tells you not to do it, your continuous integration maybe checks these things.
03:40 I think you're in a pretty good place.
03:41 And I think that more and more we're going to see as the years come on that people's workflow is just going to include type checkers with their code, with large projects at least.
03:52 Yeah, at least with large projects.
03:53 I agree.
03:53 Cool.
03:54 Well, I'm pretty excited about this.
03:56 I was really surprised to see that was in 3.8, but I'm happy to spread the news about PEP 5.9.1.
04:01 How about you?
04:02 You've got some numbers that are incrementing as well, huh?
04:05 Yes.
04:06 So, Flit, have we talked about packaging?
04:09 I know.
04:11 I don't think we have enough.
04:13 Not enough.
04:13 Let's keep going.
04:14 I'm almost positive we've covered Flit before.
04:17 Yeah, we certainly discussed it, if not made it its own pure topic.
04:20 We've definitely talked about it.
04:21 Right.
04:22 So, one of the beefs I had with Flit, which was just a minor thing.
04:26 So, Flit makes it easy so that you can, like super easy.
04:29 So, if you've got some code that you want to share with somebody, you just install Flit and say Flit init, and essentially it does the right thing to create a package for you.
04:38 You don't have to read up on setup tools or anything.
04:40 It just kind of works.
04:42 Oh, that's interesting.
04:43 It's like npm init, sort of.
04:44 Okay.
04:45 I don't know what that is, but I'll believe you.
04:47 That creates a good job of like an npm package.
04:49 Yeah, yeah.
04:49 The news right now is Flit 2 is here.
04:51 So, when initially playing with Flit, I noticed a lot of quirks with it.
04:57 So, for instance, you couldn't use a source directory to put your source code in it.
05:01 Your package needed to be a top-level directory or just a module.
05:05 That was actually a pull request that I did to try to get the source directory added to Flit.
05:12 And now it's in.
05:13 So, it's in 2.
05:13 But it also wouldn't play.
05:15 That's awesome.
05:15 Yeah.
05:16 So, when playing with it now also, it used to be that it really assumed you were going to be in a Git repository.
05:22 That's fine.
05:23 Except for when you're just playing with stuff.
05:26 Sometimes you're not.
05:27 You're just trying.
05:28 Yeah.
05:28 I want to just try this out.
05:29 I'm not committed yet to this even working.
05:31 Let's just see what happens, right?
05:32 Right.
05:33 Flit now does work without if you're not in a Git.
05:35 It determines what files to include in a package with Git stuff or with, you know, what's in Git and what's not in Git.
05:43 And I don't know how it works when you're not in a Git repo.
05:46 But right now, it does work if you're just playing around.
05:48 If you don't have anything checked in, it still works.
05:51 And that's pretty handy.
05:52 I mean, I definitely want everybody to use version control.
05:55 But if you're just trying this out, you can now.
05:57 And it's really cool.
05:58 And there's a whole bunch of improvements.
06:00 I'm linking to the release notes or the history.
06:04 It's just sort of, if you've tried it before and were frustrated, try it again.
06:08 The caveats I'd like to say is this kind of a lightweight packaging system, it does not work for compiled code.
06:16 So, it's not built yet to deal with compiled parts of it.
06:22 Right.
06:22 If I had like some Cython bits or something, it doesn't deal with that.
06:25 It doesn't.
06:25 And then there's a couple other reasons why you might not want to use this.
06:30 But for, I think, the 80% case where people are just trying to share some Python code with each other, this is the way to go.
06:37 Okay.
06:38 That sounds super cool.
06:39 Yeah.
06:40 That's what I love in the second version is your email address is optional now.
06:45 It used to be required.
06:47 But you're not required to put an email address in PyPI.
06:52 So, why require it for these tools?
06:54 Yeah.
06:55 That makes a lot of sense.
06:56 Yay.
06:56 So, now my big beef with the split not supporting source is I'm done with that beef.
07:01 You know what?
07:02 This is a super cool example as well, right?
07:04 Like, it's one thing to just complain and say, you know what?
07:08 This thing is crappy or it doesn't work the way I want or something.
07:12 It's another to say, and I'll help to make a difference, right?
07:16 So, like, the reason it supports it is your PR was merged in, right?
07:19 That's awesome.
07:19 Yeah.
07:20 And it also, it doesn't add any, I didn't add any flags, didn't add anything.
07:24 It's just within the init part of it.
07:26 It detects that your code is in a source directory and it just uses that.
07:30 Yeah.
07:31 Super.
07:31 Nice work.
07:32 Do you know what else is cool?
07:33 DigitalOcean.
07:34 DigitalOcean is very cool.
07:36 DigitalOcean is making Kubernetes easier with their DigitalOcean container registry and one-click
07:43 apps.
07:43 After building your app into Docker containers, you'll often want to store container images in
07:49 a centralized location called a container registry.
07:52 From there, you can pull images into a Kubernetes cluster or a VM, whether it's a development,
07:59 testing, staging, or production environment.
08:01 While you can post your containers' images into the open internet freely using services like
08:07 Docker Hub, clearly you don't want to do that with confidential software or, you know,
08:12 your own private stuff.
08:14 So, DigitalOcean introduced a new managed service called DigitalOcean Container
08:19 Container Registry.
08:20 And it's now available in early access mode.
08:24 So, DigitalOcean Container Registry is simple, private, secure, and fast.
08:29 And you can get started using it by going to pythonbytes.fm/digitalocean.
08:34 Cool.
08:35 I feel like this next item that I want us to talk about, I feel like we talked about it
08:39 before, but I went back and I searched and I couldn't find anything about it.
08:42 So, if we covered it like three years ago, we're going to cover it again.
08:46 Nonetheless, it deserves to be covered because it's really cool.
08:48 This comes to us from Andrew Simon and it's called Pint.
08:53 So, how many cups is in a pint?
08:55 Or do pints go into cups?
08:57 Is there, like, how many gallons go in there?
08:59 And if I had to convert that to liters or milligrams, like, what would, like, I don't know.
09:05 All these questions are completely unknown to me without, like, some chart and a calculator
09:09 or Google.
09:10 And I would suspect they are to a lot of folks.
09:12 Mixing some form of units, even if they're in the same system, like meters and millimeters,
09:20 can be tricky, right?
09:21 So, this pint thing, its job is to basically apply units to numbers and calculations in Python.
09:30 Okay, so, I'm sure you took physics and, you know, in physics or maybe even chemistry,
09:35 like, your professor would tell you, like, you cannot just tell me the number is seven.
09:39 You have to say seven what?
09:41 You have to put units on this number or this number doesn't really tell us what the answer is
09:47 or what we're working with, right?
09:48 And so, pint lets you do that.
09:50 It has all these different types of measurements.
09:52 It has, like, energy and, you know, like, joules and it has distance and weight and all these
09:59 these different types of things.
10:00 Even wavelength.
10:01 It'll help you, like, convert wavelength types of measurements and stuff.
10:05 So, if you've got some numbers you need to add together, like, for example, it's super easy to add
10:10 two meters and five inches and get the right answer in the units that you want.
10:14 Oh, that's cool.
10:15 Yeah, super cool, right?
10:16 So, I'm linking to basically a Python document that has a TXT ending on GitHub.
10:23 So, read that however you want when you get to it.
10:25 It's a little unformatted.
10:26 But it shows you all the different units and types of units that you can work with, right?
10:30 It knows what a decigram or a decimeter is and all those different types of things.
10:35 So, I just want to share a quote.
10:37 It's on the homepage there that talks on the pint.
10:40 Read the docs.
10:42 So, it talks about the Mars Climate Orbiter.
10:46 And it said the MCO has determined...
10:50 This is an orbiter that went around Mars until it didn't go around Mars anymore and it hit Mars,
10:55 I believe.
10:56 It met Mars in an unfortunate way.
10:59 It said the MCO Mission Investigation Board, MIB I'm guessing, that's what that stands for,
11:06 has determined the root cause for the loss of the MCO spacecraft was a failure to use metric units
11:11 in the coding of the ground software file, small forces, used in trajectory models.
11:16 Specifically, the thruster performance data in English units instead of metric units
11:22 was used in the software application titled SM underscore forces.
11:25 Hence, orbiter meet planet.
11:29 So, yeah.
11:30 You know, this is not the type of code I write a lot.
11:33 So, it's not directly useful for me, but I've studied science a bunch.
11:36 And it seems if it is the kind of code you write, it's very simple and very powerful.
11:41 Yeah, one of the things I like about it is it's not the units separate so that you can look these up.
11:47 It stores the values.
11:49 It just has values with units associated with it.
11:52 And so, you can pass them around and use them in other places.
11:55 And all the math operators work on it.
11:58 And it's, I mean, if you really want to, I mean, you kind of have to know the units anyway.
12:02 But one other way to do that people have often used is like suffixing variable names with what the units are.
12:09 But then that's, there's nothing telling the software that it has to comply with that.
12:14 It's just, it's just convention at that point.
12:17 But so, if you, especially with mission critical stuff, I think this is a really great idea.
12:21 Absolutely.
12:22 So, the way you would create like three meters is you would create an instance of a unit registry.
12:27 And then you would just take the number three times meter.
12:30 Yeah.
12:31 And now it's a three meter quantity.
12:32 So, they override what the multiplication thing means.
12:35 And yeah, it's pretty cool.
12:37 That's clear.
12:37 You can add different units together like meters and centimeters together and it just works right.
12:42 And that's great.
12:43 Yep.
12:44 Nice and simple.
12:45 Yep.
12:45 Speaking of simple.
12:46 I gotta say that the unit thing that you looked at, you linked to, it has, I didn't know this, that yada is 1 times 10 to the 24th.
12:55 So, yada, yada, yada is a really big number.
12:59 I had no idea.
13:00 That's a huge number.
13:01 How interesting.
13:01 What a cool piece of trivia.
13:02 Yeah.
13:03 Okay.
13:04 Speaking of a bunch of numbers and great things.
13:07 We're gonna take a look at some pytest plugins.
13:10 So, Jeff Triplett wrote an article called Eight Great pytest Plugins.
13:15 And there was even some fun stuff for me.
13:18 I'll just list them quickly.
13:20 There's a couple that I'll highlight.
13:22 So, pytest Sugar.
13:23 So sweet.
13:24 It's just a fun one that like changes the output.
13:28 But it isn't just fun.
13:29 It like changes the output so it looks kind of nice.
13:32 You get green check marks and stuff instead of the dots.
13:34 Add the progress bar.
13:34 Yeah.
13:35 Progress bar.
13:35 Progress bar.
13:36 But it also shows failing tests instantly instead of waiting to the end or something.
13:41 So, that's nice.
13:42 It's cool.
13:43 pytest-Cov.
13:45 It hooks into the coverage so that you can, you know, more succinctly check your coverage on your code using pytest.
13:53 I use that.
13:54 It works great.
13:54 The next one I want to, which I hadn't heard of before, is called pytest-Picked.
14:01 And this is like a brilliant idea.
14:04 So, if you've ran your pytest code, you know, you think your stuff is good.
14:08 But what this one does is you're working on your code.
14:11 And if you're using Git, you've got modified and unstaged and uncommitted code within your repo.
14:18 So, that's the stuff that probably the new bugs are in.
14:21 And so, what pytest-Picked does is it only, it tests files that, it runs tests that use the files that have been changed since your last commit.
14:30 That is super cool.
14:31 It probably runs your test code that have been changed since your last commit.
14:37 But what I would love to see, and maybe it does this, you tell me if you know, is if it would look at the coverage data and it would rerun the tests that were covered by your tests.
14:48 The files that were covered by your tests but then changed, it would rerun those tests that covered it.
14:53 Oh, did I get it wrong?
14:54 Does it just run?
14:55 I think it just straight up runs the files.
14:57 It's just like if your tests have changed.
15:00 Yeah, I'm pretty sure.
15:03 It says the tagline is runs the test related to the unstaged files.
15:08 So, not sure.
15:11 Yeah, yeah, not sure.
15:11 I'll have to try that one out.
15:13 Report back.
15:13 Yeah, we definitely got to try it.
15:15 My first impression from looking at it is it runs the tests that were changed, not the code that was changed covered by the test.
15:21 But, yeah, we'll report back.
15:24 Both of them are interesting.
15:25 They're both very interesting, yes.
15:27 They're like already, I think it is a super cool idea and I love it.
15:30 If it does the second thing I said, then I'll love it even more.
15:33 Yeah, okay.
15:35 The next one is pytest InstaFail.
15:38 Modifies the default output so that failures show up immediately.
15:43 Right now, if you run pytest, if you just run it with no options, you get a bunch of dots for all your passes.
15:48 You will see the F for the fails, but you don't get the output right away.
15:52 Like what the traceback is.
15:54 And so, if you really want to like start debugging before your test suite is done, InstaFail might be the thing for you to show your failures right away.
16:02 The details of your failures.
16:04 Now, for people that really think that pytest is already giving you too much information, pytest TLDR is hilarious, but it's actually quite useful.
16:14 And it will kind of remove some of the stuff from the pytest output.
16:19 Some of the boilerplate that comes at the top and bottom and also just kind of reduces the output.
16:24 It's kind of nice.
16:25 And this is by Freakboy.
16:27 Kenneth, I'm going to get this wrong.
16:29 Keith Russell McGee.
16:30 Yeah, that's it.
16:31 Now, next one is pytest XDist.
16:33 A lot of people think of XDist as the way to run all your tests in parallel.
16:38 You can run them on multiple processors.
16:40 The surprising thing is you can also run them on not just multiple processors, but multiple instruments or multiple machines.
16:48 You can have them spawn into other computers to run tests, which is really cool.
16:55 But you can also do things like loop on fail and just perpetual.
16:59 You can just have these things just keep running.
17:01 So, that's pretty cool.
17:02 That is cool.
17:02 Just periodically just say, try it, try it, try it until it turns green.
17:06 Yeah, especially if you're actively working on a fix, why not just have that pop up whenever it's done?
17:12 Nice.
17:12 The last two are pytest Django and Django Test Plus are both things that will help you if you're testing Django,
17:20 which is not surprising that this came from Jeff Triplett because he's a Django guy.
17:26 Yeah, very cool ones.
17:27 I like these.
17:27 Although, I feel like you cheated, Brian.
17:29 I mean, we're supposed to cover like six things each show, and here you've covered eight.
17:33 Eight great pytest plugins.
17:34 Come on.
17:35 Like, who would do that?
17:36 You know, I told you I was a sucker for link bait articles.
17:40 So, listicles.
17:41 Yeah, for sure.
17:42 Well, the next one I have is 11 new web frameworks.
17:44 Oh, and you're giving me a bad time.
17:46 Not for long, though.
17:47 No, I think it's great.
17:48 It's cool to touch on a bunch of those little things real quickly.
17:51 Now, people know that I do a bunch of web development, and I'm a fan of web frameworks.
17:56 And for a long time, we had kind of the mainstays, Blast, Django, and so on.
18:02 But recently, and I feel like two things, both the type hints and the async-capable ASGI servers,
18:10 those two things have created just like a blossoming of all these different types,
18:14 because they're like, well, if we've got to rewrite it so that it supports async and await,
18:18 or if we're going to rewrite it so I can use type hints to like grab stuff out of the query string,
18:23 let's just go crazy and create all these new frameworks.
18:26 And well, 11 new ones is what we get.
18:28 Actually, more than that, because there's some that are not listed.
18:30 Some we've spoken about, some we haven't spoken about, but I've heard of,
18:34 and some I've not even heard of.
18:35 So it's pretty cool.
18:36 I'll just go down the list really quick.
18:38 One of the things that's interesting, if you look at a lot of these frameworks,
18:40 a lot of them are Flask-inspired.
18:43 like, you know, you create an app, and then you do app.
18:46 you know, decorate app.route to define it and stuff like that.
18:49 A lot of them have adopted the Flask API without actually being Flask or coming from Flask.
18:56 So anyway, so the number one is Sanic, which is a web server framework meant to go fast.
19:03 And this one is mostly focused around enabling async and await.
19:06 That's pretty cool.
19:08 Probably the most widely used, at least in terms of other projects, for the ASGI, the async type of frameworks, is Starlet.
19:17 So Starlette is cool.
19:19 Comes from, I believe, Tom Christie and folks who are involved with the Django REST framework.
19:24 And it's a lightweight ASGI framework, which is great for high-performance async and await services.
19:31 And you can either use it as its own web framework, or it's interesting as a foundation.
19:36 For example, Responder is built atop it.
19:39 I believe FastAPI may be as well.
19:41 Yeah, I think so.
19:42 Yeah.
19:42 So there's a bunch of things that are derived from it.
19:45 That's pretty cool.
19:45 And both those first two are Flask-like.
19:47 A Masonite I had, Joseph, from the Masonite team on Talk Python not long ago.
19:52 And it's interesting.
19:53 This is not an async and await framework.
19:57 It's like a standard framework like Flask or Django, at least at the moment.
20:01 But what makes it unique is it has this command line tool that lets you do things to the project called Craft.
20:08 So the Craft CLI is like what makes this kind of unique.
20:11 That was a really good episode with that interview.
20:14 And I like the example of somebody bringing in good ideas from other languages and helping out the Python community with that.
20:22 Yeah, thanks.
20:23 I agree.
20:23 It was definitely fun to talk to Joseph.
20:25 So, for example, like with a lot of these projects, you create the project and then you're on your own, right?
20:31 It's like, okay, well, I use maybe cookie cutter or some other technique to create the project.
20:35 And now I've got to write every little bit.
20:38 But with Masonite, you can actually go and say, now add this model or go add, you know, these other things.
20:44 And it'll continue to like let you evolve it using these sort of starter cookie cutter type things.
20:49 So it's cool.
20:50 FastAPI.
20:51 If I was building an API these days, I would definitely, definitely look at this.
20:55 Fast modern framework for building APIs with Python 3.6 based on type hints.
21:00 That's cool.
21:01 Responder.
21:02 This is from Kenneth Wright.
21:03 It's based on Starlette and its primary reason for existing is to bring the niceties both from Flask and Falcon over into a single framework.
21:13 That's cool.
21:13 Molten, which is a minimal, extensible, fast framework for building HTTP APIs with Python.
21:21 And it's sort of magic.
21:23 One of its magic things is it can automatically validate requests according to schemas.
21:28 So you're building an API.
21:29 It takes a JSON document.
21:30 It can validate that by saying this is what this method takes.
21:34 It takes an integer and it has this thing in the JSON document and so on.
21:38 It's pretty cool.
21:38 Jopronto, another one of the async and await frameworks.
21:42 This one's based on UV loop and Pico HTTP parser.
21:45 So it's super, super fast.
21:46 Like basically its foundation is all C.
21:48 Klein.
21:49 Have you ever heard of Klein?
21:50 No.
21:51 Me either.
21:52 But apparently it's a micro framework for Python.
21:55 And it's incredibly, it's got an incredibly small API like bottle or Flask.
22:00 Speaking of Flask, there's Cort.
22:02 This is the one that's closest to Flask because it is literally a superset of Flask.
22:06 It's so compatible.
22:07 It even takes like Flask extensions and just runs those.
22:11 But the difference here is, is it adds async and await to Flask.
22:15 So if you have a Flask app, you do a find and replace the word Flask with Cort.
22:19 And now you can use async and await and Flask.
22:21 That's pretty cool.
22:21 That's cool.
22:22 Blacksheep.
22:22 We talked a little bit about that.
22:24 This one is inspired by Flask in ASP.NET Core.
22:27 One of its bits of magic is it automatically supports binding request values into variables,
22:35 either by convention or type annotation.
22:37 So I could have a view method and it takes a username and it takes a product ID.
22:43 And I could put a little decorative that says the username comes from, I don't know, a cookie or something.
22:48 And the product ID comes from the query string.
22:52 And it'll automatically go and pull those all together and just pass them as arguments.
22:55 That's pretty cool.
22:57 And finally, wrap this up, is Cyclone.
23:01 Another one I have never heard of, but it's a framework that implements the Tornado API
23:05 and the Twisted protocol to bridge Tornado's Elegant API and Twisted's Event Loop, enabling
23:12 a vast number of protocols.
23:13 So very, very cool.
23:14 Yeah.
23:15 So unlike my list, you should not use all of these at once.
23:18 No.
23:19 Yeah.
23:19 Your list would be great.
23:20 If you try to use all these at once, yeah, you're just going to mess things up.
23:24 It's not good.
23:24 Like pick one or maybe two.
23:26 Maybe if you have APIs and you've got a web framework, but you probably don't even need
23:30 to do that.
23:31 Just pick one.
23:32 Or you could end up with like crashes and exceptions.
23:35 All sorts of error messages.
23:36 Yeah.
23:37 And one of the things that there's an application I'm thinking of doing that I assumed I would,
23:42 I don't want to do, go crazy with the micro, micro architecture.
23:45 What are those things called?
23:47 Micro frameworks?
23:48 Not the micro frameworks, but like the whole bunch of microservices.
23:52 That's it.
23:53 Oh, yes.
23:53 However, things like FastAPI and stuff make it so easy to write the API part that I am
24:00 thinking about doing like a two, two level thing of doing a FastAPI and then a, and then
24:06 a web interface based on that.
24:08 It's just two services.
24:09 It seems totally reasonable.
24:11 Yeah.
24:11 It seems fine.
24:12 And with engine X and stuff, you can put it under the same domain and just put like proxies
24:16 to different parts of your app based on like slash API or not slash API.
24:21 Oh, cool.
24:23 So the deployment is really easy.
24:24 It's a good thing I have friends like you.
24:26 Yeah.
24:26 Yeah, that's right.
24:27 Happy to help.
24:28 So next up, I want to talk about exceptions.
24:31 Like I am exceptional and you're exceptional.
24:33 We're all exceptional.
24:34 Everyone's special.
24:35 We're all snowflakes.
24:36 Yes.
24:37 This is a nice article that just came out this November called raise better exceptions
24:43 in Python.
24:43 So this is just sort of a, I guess, kind of like a public service announcement, actually
24:49 kind of a nice article though, about when you're raising exceptions, it's, you know, you
24:54 throw an assert in sometimes to be like that.
24:59 I should really never get here, but exceptions are not really unexpected things.
25:04 There, you should be, your software should handle it.
25:07 It's really bad if you're, if your software is not handling exceptions at the top level.
25:12 However, often exceptions will happen if like you're raising from a trial, you try some stuff,
25:18 you grab a value error or something, and then you raise a more meaningful exception.
25:23 That's a pattern that's often used.
25:26 The article's really pointing at just don't put like f-strings with value stuff within your, just all within one string as a value error or any sort of, just don't just like try to bundle it all together.
25:40 The point is most exceptions, unless you've mucked something up in the init, most exceptions take a unlimited number of parameters.
25:49 So if you want to raise an exception with a whole bunch of values for your exception handler to, to be able to introspect and use, just put them in, put them in more parameters in the list of the constructor to the exception.
26:03 That's super cool.
26:04 And I honestly, I didn't know about this.
26:06 This is great because to the example is if I raise a value error and the message is the value is too small, it's like, okay, great.
26:13 So now what?
26:14 Maybe you can't even get back to like what the value was because the way, you know, it got passed around or it wasn't in a variable.
26:20 So what can you like report on that value?
26:23 Could you log the value?
26:24 Whatever, right?
26:25 But if you can just say, here's the message, comma, thing one, thing two, thing three, thing four, and it just appears in the exception.args later and you can deal with it in your catch clause.
26:35 It's great.
26:36 Right.
26:36 And some people will realize that, but not realizing that you can put them as parameters, but realize that you want to know the value.
26:43 So they'll try to put the value in a string, but that depends that it depends on the wrapper function or the stir function being valid.
26:53 And maybe that's the thing that blew up in the first place.
26:57 So, yeah.
26:58 Exactly.
26:58 It's simple, but it's going to be really handy.
27:00 Yeah.
27:01 Love it.
27:02 All right.
27:02 Well, that's it for our main items.
27:04 You got anything extra you want to chat about quick?
27:06 Yeah, I did.
27:07 It showed up on your list, but I'm going to bring it up anyway.
27:10 So I was reading around on realpython.com and I came across this thing.
27:14 I don't know, there was this guy that was being interviewed.
27:17 It said, a Python community interview with Brian Okken.
27:20 Yep.
27:20 I did that thing.
27:21 Awesome.
27:23 That's cool.
27:23 Yeah.
27:23 So if people want to learn more about you, they can go check out this interview on real Python, right?
27:27 One of my favorite questions and answers is the question of, how did you get into testing?
27:32 And really, I never did.
27:35 I've always been a software engineer.
27:37 So that was a fun question to answer.
27:39 That's cool.
27:40 Anything else?
27:41 Yeah.
27:41 I got two more things I want to talk about.
27:43 One of them comes from Brett Cannon, sort of.
27:45 It also had you appearing on this little list of mine that I've got.
27:51 So Brett Cannon put out a poll and the poll said, if you typically keep your virtual environment locally with your code, as I do, like so at the top level of your project folder, what do you call it?
28:02 Is it venv?
28:04 Is it dot env?
28:05 Is it dot venv?
28:07 Is it something else?
28:08 And so on.
28:09 And that's pretty interesting.
28:11 You can see the polls straight up.
28:13 No dot venv is what came up the most.
28:16 That's what I've migrated towards these days, mostly because some of the tooling works better than the hidden ones or dot env.
28:23 But, you know, you've got some replies in here and all sorts of stuff.
28:27 But the one that caught my eye the most, and I think maybe you commented on it, was from Brian here, as in Brian Skin.
28:34 And he said, I actually use the ability to change the prompt name, right?
28:40 So normally when you activate that virtual environment, it would just say parentheses venv.
28:45 And you're like, okay, super.
28:46 So something somewhere in my entire computer is different about Python and but which, right?
28:53 But if you do --prompt equals, you can give it a name so that when you activate it, it says, you know, like Python Bytes Web App or whatever it is you want.
29:03 Yeah, I always use that.
29:04 You do?
29:04 That's cool.
29:05 Yeah, because otherwise all my virtual environments are named venv, and that's boring.
29:11 That's quite boring.
29:11 So, yeah, it's pretty cool.
29:12 And you can even pair that with, like, the read command and then take that.
29:16 So when you create the virtual environment, you could set up a script that will ask, what do you want your prompt to be called?
29:21 And then it'll just put it into the virtual environment.
29:23 So when it activates it, it converts it over to that, which is pretty cool.
29:26 So my request is, I haven't actually requested this yet, but I would like it to be the name of the directory that the virtual environment is in.
29:35 Not the venv one, but the parent directory.
29:38 Yes, that would actually almost always be the right answer, wouldn't it?
29:41 Yeah, it's usually my project name.
29:43 That's what I want to know.
29:44 So that's what I'd like.
29:46 And then Al Swigert said, I use venv.
29:49 Al said he uses dot venv for the reason that you shouldn't muck with it.
29:56 It's just there, but you shouldn't change it.
29:58 And I'm frustrated that he's right.
30:00 And I think I'm going to try using it with a dot from now on, or for at least a little while and see what I think.
30:06 Yeah, the reason I like not having the dot is when I'm in the Finder, if I go over there, I can see, okay, this one already has a virtual environment set up.
30:16 I haven't been on this project.
30:17 It was in GitHub.
30:18 It's been like six months.
30:19 I come back to it like, do I need to create a virtual environment?
30:21 Or is there already one here?
30:23 I just go activate.
30:24 In Finder?
30:24 You can't see the dot files?
30:26 No, it hides them.
30:28 That's hidden.
30:28 Oh, I guess I use command line more than anything else.
30:31 Yeah, yeah.
30:31 So if you want to see them in Finder, you have to go into the dot folder.
30:34 And then you can say open dot or open that folder.
30:37 And then it'll like be half grade out in Finder.
30:40 But if you just browse to a project, you won't know whether or not it has a virtual environment if it's a dot something.
30:47 Okay.
30:47 Anyway, it's not a huge benefit, but that's why I kind of stopped using the dot, which I had been before.
30:51 So for the subset of people that are on Macs but don't like a command line.
30:57 I also like the command line, but I don't exclusively use it, right?
31:02 Okay, okay.
31:03 All right.
31:03 Anyway, this is a whole long discussion about this.
31:06 And I thought it was actually pretty interesting, all the threads there.
31:09 Yeah.
31:10 Yeah.
31:10 Pretty cool.
31:10 All right.
31:11 Last thing.
31:11 I told you about a new course last time, right?
31:13 Yeah.
31:13 Well, since then, I wrote another course and recorded it.
31:16 And I think this one's going to be really fun for people as well.
31:18 I wanted to write a course for people who are team leads, who are decision makers at their company.
31:26 And they're trying to decide or they're working with their team to decide, like, should we adopt Python or is Python the right thing for this project or not?
31:32 So I wrote a course called Python for decision makers and business leaders.
31:36 If you need ammunition to help sell Python in your organization, or if you want to know, like, maybe when it's not the best choice.
31:44 Like, this talks to all those things.
31:46 And it also looks at, like, the job market and hiring developers and all kinds of random stuff that I think those groups would care about.
31:52 So, anyway, another course is coming shortly.
31:54 That's really cool.
31:55 Yeah.
31:55 Thanks.
31:56 I might want to do an alternate course of Python for indecisive cogs.
32:00 You might want to work on the name.
32:04 It might not, like, attract, like, you know what?
32:06 I am an indecisive cog.
32:08 I will.
32:08 Maybe.
32:10 Yeah.
32:10 Yeah.
32:11 Maybe.
32:11 Maybe.
32:11 Anyway, it was a lot of fun to put together.
32:13 And it'll be out pretty soon.
32:15 Okay.
32:15 You got a joke for us?
32:16 I got something for you.
32:17 You can tell me whether it's a joke.
32:19 So this comes to us from Daniel Pope.
32:21 He didn't send it in.
32:22 I just found it on the internet.
32:23 And it was his joke.
32:23 So I'm going to, at least, it came through him.
32:25 So I'm going to share it.
32:26 This one is about farm implements.
32:29 Okay.
32:30 Okay.
32:30 What is a tractor's least favorite programming language?
32:34 I don't know.
32:35 What?
32:35 Rust.
32:36 That's bad, right?
32:38 Definitely a groaner.
32:40 Yeah.
32:40 But that reminds me.
32:41 So how do you tell when a joke is a bad joke?
32:45 When it's fully grown?
32:47 Oh, that's a good one.
32:49 I like it.
32:49 Thanks a lot.
32:51 Yeah.
32:51 Yeah.
32:51 Thanks for being here, Brian.
32:52 It was fun.
32:52 Bye.
32:52 Yeah.
32:53 Bye.
32:53 Thank you for listening to Python Bytes.
32:55 Follow the show on Twitter at Python Bytes.
32:57 That's Python Bytes as in B-Y-T-E-S.
33:00 And get the full show notes at pythonbytes.fm.
33:03 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
33:08 We're always on the lookout for sharing something cool.
33:10 This is Brian Okken.
33:12 And on behalf of myself and Michael Kennedy, thank you for listening and sharing this podcast
33:16 with your friends and colleagues.