Python Bytes - #239 No module named pythonbytes

Episode Date: June 23, 2021

Topics covered in this episode: ormar: an async mini ORM for Python, with support for Postgres, MySQL, and SQLite. No module named JupyterLite Lot of plots Monty, Mongo tinified. MongoDB implemente...d in Python Exhaustiveness Checking with Mypy Extras Joke See the full show notes for this episode on the website at pythonbytes.fm/239

Transcript
Discussion (0)
Starting point is 00:00:00 Hello and welcome to Python Bytes, where we deliver news and headlines directly to your earbuds. This is episode 239, recorded June 23rd. It's almost the end of June. Wow. 2021. I am Brian Akin. I'm Michael Kennedy. And I am Nick Mo. Welcome, Nick. Thanks for joining the show. Before we jump in, tell me a little bit about yourself. Yeah, sure. So as I said, Nick Mo, I'm based out of Ohio, and I work as a data engineer at Trimble Transportation. It's a software company. I mean to like revolutionize the way we supply the world and like simplify and connect like the world supply chain.
Starting point is 00:00:38 Like it tries to make it easier to move goods and freight all around the world. I'm also the co-organizer of ClePi, which is Cleveland's Python meetup group. Thank you, Michael, for sharing it on the screen. So yeah, that's a bit about me. Nice. I enjoyed Cleveland when we were there for PyCon. Yeah, I think I met you guys there. Cool.
Starting point is 00:01:00 I think you guys were in the JetBrains. That's right, we were. It was really great to be in Cleveland for a couple of years. And I guess we just completely missed Pittsburgh, but they're going to get another round out of here as a redo, which is cool from COVID. I got a chance to speak at the Cleveland Python meetup and talked about memory.
Starting point is 00:01:20 Was that right? Yeah, you talked about how Python manages memory. It was like a really cool deep dive into that. Yeah, thanks. That that was super fun for having me now it's good to have you on our show yeah so was that on purpose did you make a joke that you couldn't remember what the talk was about no i i know how my brain might store the memory of what i spoke about but i just it could have been that or async and and I wasn't 100% sure which one it was. We did talk about async too, though. Cool.
Starting point is 00:01:49 Yeah, for sure. Speaking of async, Brian, async databases, tell us about it. Well, this is object relational mappers also. So we have Ormar, which is an async mini ORM for Python, which supports Postgres, MySQL, and SQLite. This was a suggestion sent to us by John Hagan. So thanks, John, for sending this in. And I actually haven't played with this a lot. I was looking around.
Starting point is 00:02:17 It looks pretty neat. But I'm going to quote John here. He says, it's a really cool ORM that combines Pydantic models and SQL models into a single definition. What is great about this is it can be used to reduce the repetitive duplication between the models for an ORM and the Pydantic models for that fast API needs to describe serialization. So I guess you do have to specify that twice normally. Yeah, normally what you do is you would have the data model, the classes that do the exchange on the API level.
Starting point is 00:02:51 So those would probably be Pydantic. But maybe then you have something like a SQL Alchemy model. And then somewhere in the middle, you've got to copy the SQL Alchemy data over to the Pydantic model, send out over FastAPI, and you get it back. Then you've got to copy that from FastAPI and Pydantic model, send out over FastAPI, and you get it back, then you've got a copy from FastAPI and Pydantic back into SQL Alchemy.
Starting point is 00:03:08 And because SQL Alchemy types are not really meant to be transferred on the wire, you don't get the open API documentation that you get from Pydantic integration and all those sorts of things. So that's normally what happens. But if your database model can also be a Pydantic model, then you don't do that back and forth.
Starting point is 00:03:24 Yeah, and anytime you've got duplication, it's like that dry issue of just you're going to mess it up sometime. It's going to be wrong. And I think that's why SQL Alchemy, I think in version 1.4, they've been playing around with a lot of ideas on how to integrate
Starting point is 00:03:40 data, not Pydantic, but data classes and the ORM style base models for different like propositions of how that should be done, but it's not yet perfect. So I think that's something that this, it looks like they could learn from Omar here. Or at least it's good to have these sort of experiments going on for everybody to look around and see how do we move forward so that we can do this cleanly.
Starting point is 00:04:07 Yeah. The one thing I will say is that with all of these ORMs, I don't know why they never give some love to SQL Server. I always see Postgres, MySQL, and SQLite, but SQL Server is pretty cool too. Where is the support for that? What's SQL Server? So that's like Microsoft's, you know what?
Starting point is 00:04:27 Fair point. I think it really matters what audience you're addressing, Nick, right? So if you're talking startups and a lot of the open source crowd, yeah, it's all Postgres. Or, you know, if you're talking to Michael, it's all MongoDB, right? But if you're talking to enterprises, boy, oh boy, do a big bunch of those enterprises run on the Microsoft stack. Windows, Windows servers, Microsoft SQL server. And that's a non-trivial amount of the use cases for these things.
Starting point is 00:05:02 So I agree that it should get some attention, even if it's not necessarily the one that the maintainers or many of the people are most keen to use. Yeah, and I agree. It was a joke, but anyway. I know. One of the things I wanted to point out that John mentioned is that one of the benefits of Ormar is there's a quick start specifically for fast API.
Starting point is 00:05:24 So you can look at the documentation and there's a quick start specifically for FastAPI. So you can look at the documentation and there's a FastAPI quick start on how to get this running with FastAPI. What an interesting combination of descriptors from the ORM class side and Pydantic models you get here. So for this, we have like the Pydantic model-based type of thing. We've got the column specified with type information the Pydantic model-based type of thing. We've got the column specified with type information that Pydantic would use.
Starting point is 00:05:49 But then you set them to things like an integer column that's a primary key or a string that has a max length setting and things like that. Yeah, it's like the worst of every world. But it's better than repeating stuff, right? So, yeah, interesting. Yeah, I think it's better than repeating stuff, right? So yeah, interesting. Yeah, yeah, I think it's pretty good. And Nick, you mentioned SQL Alchemy and data classes. Pydantic also has some integration for working with data classes as well.
Starting point is 00:06:15 So maybe there's a way to bridge those things across for like FastAPI and similar situations as well. I haven't tried that, but it's possible. Yeah, let's see. Out there in the live stream, we've got Sam Morley. Hey, Sam. Says this looks a lot like a Django ORM. Yeah, absolutely.
Starting point is 00:06:29 It really does. And then Dean is hoping that we'll get some support for a very important database, AccessDB. That and, oh gosh, what was it? DB2 and a couple of the others.
Starting point is 00:06:40 Yeah, there's some really important ones that I might be forgetting, but I think it's going to be okay. Oh man, Access, that gives me PTSD from college. Probably others. Yeah, there's some really important ones that I might be forgetting, but I think it's going to be okay. Oh, man. Access. That gives me PTSD from college. I can imagine. I can imagine.
Starting point is 00:06:51 All right. Well, speaking of people who might be getting some trauma, let's talk about NoModuleNamed. NoModuleNamed.com, in fact. It's now its own website. You used to think of it as like an error and now it's actually a service. So error explanations of a service, I guess is what you would call it. All right. So Gareth Doon pointed out that there's this website called no module named and it looks super plain. And I went to like, what is this? It has 3,626 packages.
Starting point is 00:07:27 And oh my goodness, like 2 million modules or something like that. And it has 151,000 package install guidelines. So for example, what if I'm working with HTTPX and I get the message that says Python error, no module named HTTPX, right? This is what you would have if you wrote import HTTPX and you went and tried to run it, but you were new and you didn't realize there were external dependencies or that HTTPX wasn't built into the standard library.
Starting point is 00:07:51 You would get that error, right? Yeah. So this tells you how to fix it. It says, oh, this is probably because you don't have the package HTTPX. Let's see if I can go something like fast API dot responses. Is that a thing? And what will it tell me if I try it? Oh, no such module.
Starting point is 00:08:07 Yeah. But so NumPy, for example, it'll give you a lot of these and it'll tell you this is probably because you don't have the package NumPy or NumPy MIPS 64 installed. So that's what I was looking for is if it would sort of show like, well, the package name is not exactly what you're looking for. So maybe BS4, right? Sometimes there's these modules that, yeah. So for example, if I say BS4, it'll say, oh, it's because you don't have, if you have the error, no module name BS4, it's because you don't have beautiful super 4 installed, right? So it's more than just like,
Starting point is 00:08:40 duh, pip install the thing that there's no module of. It tries to help a little bit more with understanding that. And it tells you how to get the module of. It tries to help a little bit more with understanding that. And it tells you how to get the latest version. It tells you how to install it. So yeah. And there's even a related article. Extremely beautiful SEO on that with people just Googling error messages as well.
Starting point is 00:08:58 Yeah. So pretty interesting. Garrett Dunn, thank you so much for sending that in. It's simple, but you know, these kinds of things can help people who are new and are getting in. And I think one of the powers of Python is we have people coming from all these different backgrounds and experiences, and they are not all computer science people that know about package managers and like love that. They're just like, oh, I know that I can do cool. I can like load this file and make a picture out
Starting point is 00:09:23 of it that I need to work on. but I get this stupid no module name this. What is this? Right. And then they can, you know, these kinds of things can help. Yeah. I'm trying to teach my 11 year old some programming and we started with packaging. Yeah. We didn't.
Starting point is 00:09:37 I know you started with virtual environments and then packaging. But Brian, I thought you would have started with testing first. I always test first. I think this is like a really, this is like a really cool project. I find it super useful when I'm working on projects related to GUIs like Qt or Phoenix. No, no, WXPython. Because like those packages come with so many underlying dependencies. And sometimes you might miss one or might miss something that is an OS dependency that you don't know.
Starting point is 00:10:12 I feel like this could help you out. And I've run through this a few times where I'm using a package that is built on top of Qt. But then it tells me you don't have PyQt GT, PyQt 5. Right, exactly. Well, I like that. I think you probably already mentioned this, but the error message is the module not found. That's often not the same.
Starting point is 00:10:35 It's not the same name as the thing you have installed. Yeah, like one that drives me crazy is DateUtil. I love DateUtil. I think it's like magic for the pain of parsing dates, that's not what you install you install python underscore date util right and so there's just it's those situations where you're like why is there no date util i pip install date util and then it's not even the right thing or you know it's it's just uh yeah i think it's helpful to sort of put those things together for people are new yeah and for people doing new packages don't do this if you can.
Starting point is 00:11:07 Even if you have the perfect name for your package, maybe come up with something else that you can actually, it's available on PyPI. Yeah, yeah, for sure. All right, Nick, you got the next one, right? Yep, I got the next one. So I was looking through Jupyter. As I said like, as I said, as a data engineer, I often use Jupyter for like data wrangling
Starting point is 00:11:29 and just trying out how to like clean up some kind of data before I actually do the actual cleaning in our data pipeline. And so I stumbled, I got the new iPad and I wanted to be like tinkering around with Python code and I was like researching into how to do that. And I stumbled across Jupyter Lite. And I was like, okay, cool, Jupyter Lite.
Starting point is 00:11:50 But sometimes I'm not going to always be connected to internet using my iPad. And then I looked deeper into it, and it's a Jupyter distribution that runs entirely in the browser and is built from the ground up using JupyterLab components and extensions. And the kernels that are available
Starting point is 00:12:12 are like in the browser. So like there's a Python kernel that is like in the browser and it's built using PyIodide. That was like really cool to see. And there's also like, I think there is a, where is it in the user guide there are other kernels such as uh yeah javascript and p5.js which i think is like a
Starting point is 00:12:34 graphics library to build like things on canvas but it was really cool to see like it's supports python 3.8 and uh you get like start session you can run python code python completion which is really cool it's interesting they call the um the kernel piolite um iolite based on pi iodide yeah and this is i pulled it on this is how it looks like and it looks pretty cool so it also supports right i think rafa now it supports altair and uh again i think matplotlib as well i think yeah and so like open up this altair notebook um it even has something called micro pip which is like uh i i don't know what this means but if I think it means that it's a package manager,
Starting point is 00:13:28 but for the browser, for Python, which is interesting. And it's asynchronous because it's JavaScript basically, right? So it's a wait, micro pip installed, like Jinja too, or Altair, something like that. How interesting. That's very cool. I think it also, everything that you download and everything that, all the data that you like load up,
Starting point is 00:13:52 it's being stored in the browsers, like local storage or some other, I don't know, index DB. So it's like self-contained. The only thing I noticed is that right now, it's not, what was the word here? A PWA. So- Yes, I was just thinking it would be fantastic
Starting point is 00:14:13 if that was a progressive web app and then you could just have it in mostly offline mode, yeah. Edge does a great job with PWAs and every time you detect like a manifest adjacent to show you do you want to install this app and I would just love to have like this click install and then have Jupiter light wherever I go or load it up on my iPad and then disconnect and still be tinkering
Starting point is 00:14:35 around be what I want this is all browser based so that's really cool I'm not gonna run any of these but I encourage everybody to check this out it It's pretty cool. Yeah, yeah, this is really cool. I do the same thing with, I use Brave, so I have like a YouTube app installed on my Mac, and I've got a Twitter app installed all as Progressive Web Apps, so you can just launch them. I do wish Firefox
Starting point is 00:14:57 supported that. Firefox people, if you're listening, bring back the Progressive Web App. We all need this. Yep. Yeah, that's cool. What are some of the other notebooks in there that look cool? Are these like demo ones or did you create these? Yeah, there's a demo one. So there's a P5.js one. There's the Altair one.
Starting point is 00:15:15 I don't know what Folium is. There's the interactive widgets, which is cool. So it still uses Jupyter's IPython notebook widgets. Math.lib. Oh, Plotly as well. And Plotly, cool. And so this is the de facto Pyrolight one. So it supports Matplotlib,
Starting point is 00:15:35 Matlab, Pandas. That's cool. It supports LaTeX as well. Yeah, it's true. And so, as I was saying before, Pyrolight is what is it? It's like implementation of Python on the browser. Actually, the implementation of Python
Starting point is 00:15:54 is on the computing stack on the browser. So I think things like Pandas, NubePy, SciPy, SciCut Learn are already like available. It's within the Pyodide ecosystem. So you don't have to... Yeah, I had the guys behind it, Firefox and Mozilla were behind it originally at least. And I had them on TalkPython.
Starting point is 00:16:12 I believe it's WebAssembly based. I think what they did is they took all these major visualization libraries and things like Pandas and NumPy and compiled them all into a Python plus those WebAssembly thing that runs in the browser instead of a JavaScript version, which is pretty awesome. Oh, you didn't say Python.
Starting point is 00:16:29 Yeah, the symbolic output, like the got the math symbol integral of the square root of one over XDX. Beautiful. I wonder if you get hand calcs on it. Oh, yeah. Awesome. Cool. All right.
Starting point is 00:16:43 Well, that's a really good one. I love it. All the data scientists out there can definitely enjoy that yeah cool what do we got next i think you're up next oh right okay um so next we've got more plotting maybe yeah more plotting so this is um uh this is a long title basically it's lots of plots um there there's eight popular graphs made with Pandas, Matplotlib, Seaborn, and Plotly Express. And one of the things, I've seen a lot of articles and stuff
Starting point is 00:17:15 talking about how to do different plots in one or more of these. And a lot of them are, a lot of the articles, and rightly so, are focused on something cool you can do with one library that you can't do with others. And I've seen Seabourn ones like that, and that's great. What I like about this article is it's like, well, let's just take these different pandas plotting and matplotlib, Seabourn, Plotly Express, and do the same plot. Let's do something they can all do.
Starting point is 00:17:45 And so that's what this article does it does um a whole list you got line normal line charts uh grouped bar charts stacked bars pies a whole bunch of things and histograms and then um you can just compare to see what it looks like before you try and you know you know, for one, it's got like, you know, the output, what are the graphs look like, which is important. But also, it's just, it's a fairly simple article. It's talking about what the plots look like, but also how do you make them? What's the, it's in a notebook viewer, Jupyter notebook viewer, and it shows you, you know, what's the code look like to get these plots set up.
Starting point is 00:18:23 And that's a, I think that's a big part of choosing your plotting library is looking at the API to see what kind of API looks comfortable to you. So. Yeah. I've got to write this code. Will I be able to remember this or will it be like regular expressions that I learn every time I use it? Yeah. Or if you get stuck with one and you want to switch to other to sort of look at what the deltas are. I like these side-by-side apples to apples comparison sort of articles. So I think this is good for choosing the simple parts of plotting, but some of the comparisons are sort of funny because like the bar charts just kind of all look the same, but.
Starting point is 00:18:58 That one's orange versus orange and blue versus green and blue. It's not all the same. Yeah. But you get down to some, some of the fancy ones and they uh yeah they do look great some of the uh what area charts um yeah that one looks great what's that uh potluck express area charts look awesome yeah the area charts look good and i didn't know what a donut chart was a donut chart pie chart with a hole in it yep why do people use that what's uh i think it's because of like with the pie charts, these sectors are kind of, sometimes it can be hard to see like how much width,
Starting point is 00:19:36 like the circumference of like this sector. So with the donut chart, it kind of makes it easier to see like, okay, this takes like all of this. It's just a visual thing, to be honest. Yeah, okay, good. Nick, this is your world. What do you think? I think this is really cool, but to be honest, all of these APIs don't compare to the grammar of graphics from R.
Starting point is 00:19:57 And so I usually use... If I am going to do graphics in Python, I would prefer to use something that, like that conforms to the grammar of graphics. Because to me, that's kind of, you know how like Python has the import this and it's all philosophy how you write Python. The grammar of graphics like has that. So it has like gives you these like sentences, so to speak, to build graphics. And I like that makes so much sense in my head. So like for a graphing lab reads,
Starting point is 00:20:28 it's either Altair or ggplot. And there is like a Python port of ggplot that's pretty good. But I think Altair is like the Pythonic de facto version that I've used that's really nice. All the other ones that make me have to do like do these method calls on objects that i've used that's really nice all the other ones that make me have to do like uh like uh like um do these method calls on objects just i can't i can't remember it i have to come back to
Starting point is 00:20:53 something like this so how do you get any map or are you using seaborne i really like the fact that like seaborne has a lot of one-liners to like do simple charts in one line which is great unlike with the grammar graphics right still makes you have to build everything out but if i'm building something really custom or i am just building something that i have i want to have complete control over the grammar graphics just gives me a better way of like remembering what to do compared to having to remember all these method API calls. The author, Dylan Castillo, says let me know what you think so maybe we can give him
Starting point is 00:21:34 some feedback to add Altair and a couple others. Oh yeah, that'd be cool. Dean also has some thoughts out there, right? Oh, Seaborn and Pandas use Matplotlib in the back end so you can do everything they can do with matplotlib. Okay.
Starting point is 00:21:47 Maybe harder, but not impossible. And also, that's probably why they look all the same. They are the same. Turtles all the way down. And he also says, remember kids,
Starting point is 00:21:58 almost every command in matplotlib returns the object it charts. That's the start of OOP, object-oriented plotting. All right, right on. OOP, and it'd be two Ps. the start of OOP, object-oriented plotting. All right, Rhino. OOP, N-A-B-2-P's. OOP, OOP, OOP.
Starting point is 00:22:09 I don't know how to pronounce that. All right, well, Brian, you got to talk about databases, so I'm going to talk about databases too. But my databases are going to be smaller and in-memory and embedded, but also about MongoDB. So there's this really cool one created by David Lotwey called MontyDB. So it's a Monty, it's a MongoDB tinyified. So it's MongoDB implemented
Starting point is 00:22:36 in Python, and you can have it in process kind of like SQLite, I believe. We've covered a couple of these libraries that are starting to show up that let you do sort of embedded MongoDB, which I think is really neat. So it's inspired by TinyDB and its extension TinyMongo. So the way you work with it, it's super simple. You just import the Monty client. And if you want to go crazy, you could say as Mongo client and make it basically the same. And then you can give it connection strings like colon memory colon. That should look familiar from something like SQLite. And then you can insert data to it, do all sorts of things and do queries against it, run like the MongoDB query syntax against it. And you get the responses back, which I think is pretty cool. It's certainly interesting for testing. If you told it to use a file storage, it could be an interesting little embedded
Starting point is 00:23:25 database and things like that. So pretty cool. It supports many of the MongoDB versions up to 4.2 and 4.4 on the way with wave emoji. I'm not really sure about that, but also supports the... What's that? I think it's sweat. Oh, gotcha. Like the work is being done. Gotcha. So you can pip install MontyDB and it will work in sort of its way. If you want to use the actual serialization library from MongoDB itself,
Starting point is 00:23:53 you can say install MontyDB bracket BSON to install that as well. It also has a lightning memory map DB, LMDB library. You can use that as the storage engine as well. So you can pip install, add that on as well. So for the storage, you've got in memory, you've got a flat file. It'll actually use SQLite as a back end store,
Starting point is 00:24:16 which is pretty cool. And then that LMDB lightning memory mapped DB. So this looks pretty neat to me. If you're gonna do some kind of embedded thing or you're gonna do some testing and you want something lightweight that's not a separate server you've got to set up and run and all those kinds of things this is cool i think it's awesome could you make this a pi test fixture brian that just gives you like preset sets up your database and gives you access to the connection or something yeah i mean i actually i don't i'm not really a fan of people
Starting point is 00:24:44 switching their databases too much for testing because most modern databases have in-memory options or smaller version options. But, I mean, we use SQLite for tons of stuff that's not just for testing. And if you've got SQLite at the back end, there's no reason why this couldn't be a production thing then. Yeah, absolutely.
Starting point is 00:25:04 No, this is really cool. This could be really useful for like CLI apps that need to store your things. Exactly. You want to have a little thing, but you don't want to say, oh, you want to run my little utility? I packaged it up with Pi 2 app or Pi 2 EXE or something.
Starting point is 00:25:20 You're going to need to install MongoDB and become an admin of that. No, you just use like a SQLite file as the back end store or the LMDB version. Another thing that's common from the MongoDB world is there's a set of CLI tools that allows you to manage it. So I can connect to it. I can import a bunch of exported files from some other or backed up files from some other MongoDB instance and import that into my current server or whatever, or create those exports, right? There's actually a bunch of utilities called Monty import, Monty export, Monty restore, Monty dump. All of these are the parallels of Mongo, Mongo dump, Mongo restore, and so on. All right. So if you were used to working with MongoDB,
Starting point is 00:26:07 it's not just explicitly that there's some API to talk to some file. There's also like the tools that are there as well. Yeah. Yeah, I don't know. I think that could be a cool project. So why did I make this? Mostly for just fun and practice on it,
Starting point is 00:26:20 but also needed to run in this limited environments for like render farms in the film industry. So that's pretty cool. It's a side project also with render farms. It's a side project for my supercomputer.
Starting point is 00:26:35 Yes. I love the name, by the way, Monty, Monty Python. I love it. Yeah, I mean, yeah, it really brings the MongoDB wordplay in with Monty Python, Python origin. Yeah, pretty cool.
Starting point is 00:26:48 All right, Nick, you got the last one. Awesome. Exhaustiveness checking with MyPy. So essentially what exhaustiveness checking is is a feature of a lot of type checkers where they guarantee that the programmer has covered all their cases and so um with my Pi you could essentially um check things like whether you've covered all
Starting point is 00:27:14 the all like you have written all the if statements you're supposed to write at compile time rather than figuring that out at runtime and I like I really got into using MyPy and trying to have it save my butt a lot in the way I think about code by embracing types. So I stumbled across this, which was really interesting, where this article written by Haki Benita went into how accessorization actually works. So they start out with a enum that has order status,
Starting point is 00:27:51 and you have a function that is called handle order that takes a status, which is an instance, which should be an instance of order status. And so in his function, he has it like if status is order ready you do something if such as his order shipped you do something but then he gave this like um i did this like new like scenario where what if you wanted to check uh the status of something scheduled and so he tried to run my pi right now i didn't complain about it so like okay cool yeah because one of the things that's very common is if you have something like a set of scheduled and so he tried to run my pyramid i didn't complain about it so like okay cool yeah because one of the things that's very common is if you have something like a set of cases in
Starting point is 00:28:30 this case it's put together in an enumeration yeah you have more cases over time but all these if else if else if else if statements all over your code have you exhaustively gone through and added that case check for all of them? Probably not. Unless you've got a good test. A really good test. Yeah. Okay. And so he proposed like one quick way of checking that you handled all cases is by adding this assert false comma on handle status.
Starting point is 00:29:01 And you pass in the status using f strings. And so then when you try to pass a state that you have not actually handled before, you actually get assertion error, right? Which is all right, but if you use mypy, there's this clever trick where you create a function called assertNever that takes a value called no return and returns no return. In it, it has the assert false on handle value. Then when you use that function in your handle order function, at the end case you have this else asserts
Starting point is 00:29:39 never and you pass in the status. Now when you check with MyPy, MyPy will know, hey, argument one to assert has incompatible type, literal, order status schedule, expected, no return. Oh, how interesting. Yeah, and this is a compile time,
Starting point is 00:29:53 and you can actually get this. Yeah, yeah, I think that's the important thing because I was looking at that going, oh, I could just add the else statement and put the assert there and have nothing to do with MyPy, and it would catch that error. But that catches that error when that code runs.
Starting point is 00:30:06 Like I said before, hopefully there's tests, but oftentimes there's not tests for everything. And so especially there might not be a test for the new thing you've added. And so this is cool in that it checks all the possible types that could go in there. That's cool. Yeah. And the part that really got me was that it integrates with your IDE. So PyCharm, VS Code, or any editor that implements a language server can then look at this and say, hey, you haven't handled all your cases, right? And you get that immediate feedback
Starting point is 00:30:40 rather than having to run your code and then find out, oh, dang it, I missed this case. Right? Yeah. So people who are not looking at the live stream, YouTube stream, which is almost all the people listening, Nick is showing on the screen, this assert function that's checking the numeration. And there's just a red squiggly line that says, literally says assert never has incompatible order status scheduled that's the missed enumeration case i think that's incredible that actually finds this yeah and it works because um my pi uses this technique called type type narrowing and essentially what that means is that it would given a variable as it goes through like a control flow like if statements
Starting point is 00:31:30 switch statements while my pi will like kind of confine or in other words narrow down the types as it goes through those control full plugins and so it works with um enumeration types unions uh literals. So I have in the article there examples of how you could pass in a union of different types, strings, float, and you could still use this technique and it will tell you, hey, you've missed a case. Or you could do this with literals. So you have like RGB and then you only check for like two cases, which are R and G. And they need to tell you, hey, you did not handle the B case.
Starting point is 00:32:12 So yeah. And so like the article goes further into different ways in which you could set this up, have my pipe check all of the different cases for you, which is really cool. You've even got like the the various sweets for cards like clubs diamonds hearts oh yeah it's interesting that like to my pie when it's season in enum that has like clubs diamonds hearts and spades all it sees is like a union of literals which are sweets cards sweet clubs sweetheart which is actually interesting
Starting point is 00:32:44 that's how my body sees it yeah that's very interesting i mean basically it's emojis yeah it's emojis right um the one other thing i wanted to mention here is that there was a specific p oh yeah this feature is actually uh something that guido actually thought was pretty cool. And so I think it's part of PEP 622 structural pattern matching already. So if you are matching against an enum or something that has multiple different states, the matching, hopefully Python 3.10 will give you a nice error saying hey you missed a particular case and this could really and if you're a django developer or you just use django or even yeah you
Starting point is 00:33:34 don't use a new rm and the rm provides something like choices where like yes no or dollar euro like these kinds of choices in the field, this works pretty well. And so in your Django code, you could actually have MyPy telling you, hey, you missed handling a particular case. Crazy. Yeah, that's awesome.
Starting point is 00:33:55 Yeah, which is really cool. Yeah, Sam out in the live stream was sort of on to the same thoughts you were talking about with Peter there. Wonder if one could hack on the match mechanism to deliver this functionality at runtime, using by somehow getting all the variants of the enum and checking the branches, the AST or something.
Starting point is 00:34:13 Yeah. That's actually interesting, because I know that part of the structural pattern matching, like any object can implement the magic method match. And maybe that is your gate, like that's your entry point into providing that kind of checking at runtime. Of course, with Python,
Starting point is 00:34:33 anything that is around runtime checking, there's like performance costs with that. So be careful. Yeah, but having this built into MyPy already would be good. And Juergen is talking about it on the live stream. He says, I wonder whether you could rewrite the code to not use if statements
Starting point is 00:34:52 at all, but be more polymorphic, which I agree it's a really interesting idea with the method overloading and stuff. And it reminds me back a couple weeks ago, Brian talked about function overloading with single dispatch and multiple dispatch. And yeah, you could kind of more or less
Starting point is 00:35:09 make that happen there. So yeah, pretty neat. Although you still may miss a case. I'm not entirely sure. At least in the enumeration bit, that won't help you, right? Because the enum will still be the same type. It'll just have more values.
Starting point is 00:35:20 Yeah. Awesome. Good one, Nick. Brian, what else we got? Well, I've got a couple of things. One of the things I wanted to note was that this is the second week in a row we've featured an article by Hockey and the third in this year. So we should probably try to get him on the show or something.
Starting point is 00:35:39 Yeah, absolutely. That sounds good. He's doing some good writing. So thanks. The other thing I wanted to mention is, is I've got, oh yeah, by the way, my book is out. This is the book too.
Starting point is 00:35:54 Yeah. Second edition by test is available for beta. So people can tell me everything that I already got. Somebody said they have got an issue. It's a minor issue with it already. So thanks. But it's just been me and my editor so far working through it. So having more people, more eyes before we go to shipping the physical book would be great.
Starting point is 00:36:17 So of course, this is through Pragmatic. But if you go to pytestbook.com, it'll take you there. So that was my extra. Right on. Cool. I got a couple as well.com, it'll take you there. So that was my extra. Right on. Cool. I've got a couple as well. Yeah, I got some neat ones here. So how often do you maybe have like a blueprint floor plan?
Starting point is 00:36:32 Maybe you're looking at a house and you're trying to decide whether you want to buy it. What would it be like to actually live there? Maybe you're trying to figure out, well, I'm planning out this apartment or I have this place. I want to remodel it like Ikea it all out or something along those lines. I ran across this thing that uses some interesting models called plan to scene. So the idea is it'll take what is literally a floor plan, like a blueprint floor plan that shows like swinging doors and bits. And then you tell it what kind of room it is. it's like a bedroom or a bathroom
Starting point is 00:37:05 or whatever and it will generate a 3d world that has things like sinks and toilets and couches that are three-dimensional not just somehow projected in there so there's all of these interesting things you can see there's like if you pull up the site there's all these like spinning worlds and you can see that they've created these little environments just from floor plans which i think is pretty insane so anyway you can go ahead nick no that's really cool i think i wonder if like because like tremble we um we own like sketchup i wonder if they do this kind of stuff they take floor plans and then they make it 3d that's really cool yeah it's uh there's a whole bunch of comparisons of how it used to be done,
Starting point is 00:37:48 how you can pick like different, you know, different flooring and walls and source codes available on GitHub. People can run with that. So that's pretty cool. It's called plan to scene. And then just a quick shout out to this TCast podcast I happen to be a guest of recently.
Starting point is 00:38:02 And we got to talk about python and data science and how python and data are sort of changing the world and stuff and it's really fun so people can check that out yeah and that's it for the things i got nick anything else you want to throw out there yeah just a shameless plug as i said earlier um on the live stream i co-host the ClePi, which is Cleveland's area Python meetup group. And so we have meetups every second Monday of the month. And one of the reasons why I would encourage anybody across the world or U.S. or everywhere to still come and present is because oftentimes meetups are a great place to present talks that you are planning on giving and maybe like continental conferences or like other larger conferences,
Starting point is 00:38:54 you know, smaller crowd. And, you know, we show you guys a good time, right? So it's a great place to come, give your talk, get feedback from that, and then, you know, take any and improve on it. So that's one. And then the other streamless blog is that PyOhio has its own conference coming up on July 31st. Registrations are open. We have pretty cool T-shirts. So, yeah, register.
Starting point is 00:39:24 And is that live or streaming? Yes, that is being streamed. Okay. How about your meetups? Are those being, are those streamed or live? Those are virtual. We used to have them like in person. And that's, I really, that's when like pandemic really messed things up because you have to have like pizza over and just have a good time talking about Python.
Starting point is 00:39:43 But no, virtual um setting has given a lot more people access um you know we're able to put more people on so nice yeah that's fantastic and py ohio is definitely one of those big regional conferences a lot of people pay attention to even if they're not in ohio are you going to go back to in-person only are you going to do like a hybrid stream and in-person or is it going to be, what's your plans for when the world returns to normal? That's if it ever returns to normal. I think we'll change forever. But to answer your question,
Starting point is 00:40:16 I think my co-organizer and I have been thinking about it. We're not on a set yet. Like we see the benefits of the virtual, but we also see the benefits of the virtual, but we also see the benefits of the live. Things have changed so much. We don't even know whether the live person is still available. But no, it's something we're thinking about.
Starting point is 00:40:35 Cool. Well, it's a challenge. I think all the meetups and other events are having, especially these smaller, monthly, bi-weekly sort of things. It's one thing to say that there's going to be a big conference and we'll all go to it or not, but you're doing it every couple of weeks and it's mostly local, but not a hundred percent local.
Starting point is 00:40:52 Yeah. It's a challenge. Yeah. Fantastic. All right, Brian, you ready for a joke? Definitely.
Starting point is 00:40:58 Okay. So I've, I've got one and then Nick has one. So this one, the title of the joke is root beer float. Okay. So a programmer walks into a bar he orders 1.000000119 root beers the bartender says i'm gonna have to charge you extra that's a root beer float the programmer says well in that case make it a double it's bad right that's that's bad yeah all right Nick, you've got one as well. You want to do this one for us?
Starting point is 00:41:28 Yeah. Would someone like to join? You want me to be the bearded person? Yeah, I really have something going on there. All right. So will refactoring the code improve the loading time? Not really. Will it improve the security then? No. So it's for browser compatibility? Yeah, no, not really. Will it improve the security then? No. So it's for browser compatibility?
Starting point is 00:41:46 Yeah, no, not really. Nope. So tell me, why is it always the same old story with you guys wanting to refactor everything? I need to know. Because as devs, if we know, excuse me, if we know we've left behind some messy code, we can't stop thinking about it. We wake up in the morning, at lunchtime,
Starting point is 00:42:04 in the evening, when we go home and when we're trying to go to sleep, it haunts us, you know, it haunts us. I love it. And it's true too. Totally true.
Starting point is 00:42:18 It's totally true. All right. I have one more joke for you guys. Oh yeah. All right. How much does a chimney cost? No idea. Nothing. it's on the house very good that's i have a friend that is so so into dad jokes which is weird because it's only 22 practicing practicing for the future yeah i don't think dads can be blamed for all bad
Starting point is 00:42:46 jokes. Anyway. Yeah, I want to highlight Juergen says that they cost 2,500 euros. That's expensive. Well, thanks a lot for joining us today. This was a lot of fun. And thanks everybody in the stream
Starting point is 00:43:03 for showing up and we'll talk to everybody next week. Thanks. Bye everyone. Bye.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.