Latest / Talk Python To Me / #539: Catching up with the Python Typing Council
Transcript
- 0:00You're adding type-ins to your Python code.
- 0:02Your editor is happy, autocomplete is working great,
- 0:05but then you switch tools
- 0:06and suddenly there are red squigglies everywhere.
- 0:09Who decides what a float annotation actually means
- 0:12or whether passing none where an int is expected
- 0:15should be an error?
- 0:17It turns out there's a five-person council
- 0:19dedicated to exactly these questions
- 0:21and two brand new Rust-based type checkers
- 0:25are raising the bar as well.
- 0:27On this episode, I sit down with three of the members
- 0:29of the Python Typing Council,
- 0:31Jelle Zijlstra, Rebecca Chen, and Carl Meyer
- 0:34to learn about how the type system is governed,
- 0:37where the spec and type checkers agree and disagree,
- 0:40and I get the council's official advice
- 0:42on how much typing is just enough.
- 0:45This is Talk Python To Me, episode 539,
- 0:49recorded January 27th, 2026.
- 0:53Talk Python To Me, yeah, we ready to roll.
- 0:56Upgrading the code, no fear of getting old.
- 0:59Async in the air, new frameworks in sight,
- 1:01geeky rap on deck.
- 1:03Quart crew, it's time to unite.
- 1:05We started in Pyramid, cruising old school lanes,
- 1:08had that stable base, yeah, sir.
- 1:09Welcome to Talk Python To Me,
- 1:10the number one Python podcast for developers
- 1:13and data scientists.
- 1:14This is your host, Michael Kennedy.
- 1:16I'm a PSF fellow who's been coding for over 25 years.
- 1:20Let's connect on social media.
- 1:22You'll find me and Talk Python on Mastodon,
- 1:24Bluesky, and X.
- 1:25The social links are all in your show notes.
- 1:27You can find over 10 years of past episodes
- 1:30at talkpython.fm.
- 1:31And if you want to be part of the show,
- 1:33you can join our recording live streams.
- 1:35That's right, we live stream the raw,
- 1:37uncut version of each episode on YouTube.
- 1:39Just visit talkpython.fm/youtube
- 1:42to see the schedule of upcoming events.
- 1:44Be sure to subscribe there and press the bell
- 1:46so you'll get notified anytime we're recording.
- 1:48This episode is brought to you by Sentry.
- 1:50Don't let those errors go unnoticed.
- 1:52Use Sentry like we do here at Talk Python.
- 1:53Sign up at talkpython.fm/sentry.
- 1:57And it's brought to you by
- 1:58our Agentic AI programming for Python course.
- 2:02Learn to work with AI that actually understands your code base
- 2:05and build real features.
- 2:07Visit talkpython.fm/agentic-ai.
- 2:11Jelle, Rebecca, and Carl,
- 2:14welcome to all of you type-loving Pythonistas.
- 2:18Awesome to have you here on the show.
- 2:20Thanks for being here.
- 2:20We're going to talk Python typing,
- 2:23especially from the perspective of the Python Typing Council,
- 2:27which honestly, I am a huge fan of Python typing.
- 2:30It's still something I learned about not too long ago.
- 2:33So I'm going to be learning along with everyone else,
- 2:35what it is you all do and so on.
- 2:38So I'm really excited to be diving into this.
- 2:41I think since types came to Python,
- 2:44I think it's made it a little bit more rigorous,
- 2:46you know, for all those people out there like,
- 2:48oh, it's not a real language without any form of static typing.
- 2:51We can't use it on real projects.
- 2:53I don't know how true that was,
- 2:54but certainly it's less true now.
- 2:56You know, you can pick per project.
- 2:58So it's super cool.
- 2:59Before we get into all that, though,
- 3:00let's just go around for a quick introductions.
- 3:03Jelle, welcome to the show.
- 3:05Awesome to have you here.
- 3:06Who are you?
- 3:06Hi, yeah.
- 3:07Jelle, I've been on the Python Typing Council
- 3:09since the beginning.
- 3:10I helped set it up a couple of years ago.
- 3:12Outside of the typing work,
- 3:13I currently work at OpenAI,
- 3:15where I work on developer productivity,
- 3:17which means things like running CI for people
- 3:19and helping, generally helping people be productive.
- 3:23I've been working with Python for more than a decade.
- 3:25Started out because my previous job was mostly in Python
- 3:28and then got more and more involved with the language.
- 3:32So let me get this right.
- 3:33At OpenAI, you're basically helping developers there
- 3:36have better developer tooling
- 3:37and common packages and workflows and stuff like that.
- 3:41Is that kind of the story?
- 3:42That's right.
- 3:43Mostly around things that happen in CI,
- 3:45like running tests efficiently,
- 3:47figuring out the right tests to run,
- 3:49getting the right CI workers out.
- 3:50That sounds very exciting.
- 3:51Right in the epicenter of all the big tech stuff these days.
- 3:56Super cool.
- 3:57Rebecca, hello.
- 3:58Welcome.
- 3:58Hey, thanks for having me.
- 4:00I'm Rebecca.
- 4:01I've been on the Typing Council also for about three years,
- 4:05I think, since the, less than three,
- 4:07since the beginning.
- 4:08But my day job, I work at Meta on Python typing,
- 4:13gone Pyrefly, which is a new type checker
- 4:16and language server written in Rust, still in beta.
- 4:20Prior to that, I was at Google for eight years,
- 4:23also on the Python team.
- 4:24I just, I really like Python.
- 4:26Yeah, super neat.
- 4:27I'm a big fan of both Pyrefly and ty,
- 4:30which will both have representatives here, I know.
- 4:33And I think it's just a super exciting time for Python types.
- 4:37And certainly that's one of the reasons.
- 4:38So very cool.
- 4:39Carl, welcome back.
- 4:40Thank you.
- 4:41Great to be here.
- 4:42Yeah, Carl Meyer.
- 4:43I currently work at Astral, where I work on ty,
- 4:48which is a Python type checker and language server
- 4:50written in Rust, also in beta.
- 4:53And yeah, I guess, how did I get into typing?
- 4:55Or I've been on the Typing Council, not since the beginning.
- 4:59I think it's been a year and a half.
- 5:01And yeah, I got into Python typing at the time in 2016, 2017.
- 5:07I was working at Instagram.
- 5:08And that was in the very early days of Python typing.
- 5:12The PEP 484, PEP 483, the early Python typing PEPs
- 5:17had recently come out within the last couple of years.
- 5:19And one of the co-authors of some of those PEPs,
- 5:21Łukasz Langa, was actually sitting at a desk
- 5:24right next to me at the time.
- 5:25And at some point, we started to think
- 5:27that we should try this Python typing stuff
- 5:28on the Instagram server monolith.
- 5:31And so I took that on as a side project.
- 5:33And then it eventually became the main project.
- 5:35And then it took like three years.
- 5:37So a lot of Python typing experience there.
- 5:40There absolutely is.
- 5:40You know, I think a couple of things
- 5:42I'd like to touch on there.
- 5:43First of all, Instagram, is it maybe the biggest Django
- 5:47deployment in the world?
- 5:48It's certainly one of the bigger ones, right?
- 5:50And I think a lot of people don't necessarily
- 5:51know that a core chunk of Instagram is actually Python, right?
- 5:55I mean, I don't know if we have any way to know
- 5:57how big the Django deployments in the wild might be.
- 6:00But it's certainly a big one.
- 6:01Yeah, it's definitely a big one.
- 6:02There were some talks about dismissing the garbage collector
- 6:06from the Instagram folks.
- 6:08That wasn't you giving the talk, but at PyCon.
- 6:11So that was pretty interesting.
- 6:12But I think actually that work that you're talking about,
- 6:16especially with Łukasz, really kind of opened
- 6:19a lot of people's eyes about Python typing, right?
- 6:22He gave a couple of PyCon talks, showed, you know,
- 6:25real metrics of how much of the code base is typed,
- 6:28how much it's changed, like error detection,
- 6:32that kind of stuff.
- 6:33So let me ask you, do you feel like it would be different?
- 6:36Would it have gone different now if tools like TY
- 6:39and Pyrefly existed back then?
- 6:42Is Python typing different now than it was then?
- 6:44Certainly, yes.
- 6:45I mean, there's been, the type system has gotten
- 6:47more complex over time.
- 6:49So it is both more expressive and more complex.
- 6:52And yeah, we have more type checkers available now.
- 6:56I do agree that it's more complicated,
- 6:58and I don't know how to feel about that.
- 6:59It is more expressive, but I feel like it's starting to get,
- 7:03I mean, we're not at C++ ATL,
- 7:06like templates of templates of templates,
- 7:09but still, it's getting more serious.
- 7:12But I guess one of the really nice parts
- 7:14is that you can just take as much as you want
- 7:16of the complexity, and you can just leave the rest, right?
- 7:19That's part of the magic of Python typing,
- 7:21is that it's a gradual typing system.
- 7:23That's a choice people get to make.
- 7:25It can be none, it can be quite a bit,
- 7:28and anywhere in between.
- 7:30So I guess that's probably one of the decisions.
- 7:33Let's talk about the typing council.
- 7:34So when did the typing council come along,
- 7:37and did the typing council exist to create
- 7:40all of these PEPs and make this happen,
- 7:42or was it afterwards?
- 7:43Like, what's the history of the typing council
- 7:45and its purpose, folks?
- 7:47We'll run it.
- 7:47Yeah, it postdates most of the PEPs.
- 7:49So initially, the text system was created
- 7:51just through the regular PEP process.
- 7:52It means that something gets submitted,
- 7:54first still to Guido as the BDFL,
- 7:57later to the steering council.
- 7:59Meant that it's very hard to make changes
- 8:01to, like, this specification.
- 8:03Like, anytime you want to make change something
- 8:04about how the type systems would work,
- 8:06we had to go through this PEP procedure,
- 8:09talk to the steering council,
- 8:09who are very busy people,
- 8:11who deal with a lot of other aspects
- 8:12of the language other than typing.
- 8:14So Shantanu and I came up with this idea
- 8:17of creating a separate council
- 8:19to specifically in charge of typing,
- 8:21that would be in a specification
- 8:22where we can make small changes ourselves
- 8:25without having to go through
- 8:26this whole PEP process.
- 8:27And this way, when all the type checkers
- 8:29agreed that something needs to go a certain way
- 8:31and it's not exactly what's in the PEPs,
- 8:33we can change it and have a place to record that
- 8:36and people can refer to it
- 8:37and new type checkers can also try
- 8:39to follow those decisions.
- 8:41Very interesting.
- 8:41I didn't realize that it was sort of,
- 8:43was there to allow for small changes
- 8:46to be made to make that much easier.
- 8:48But of course that makes sense
- 8:49because the PEP process is,
- 8:50it's pretty serious and drawn out.
- 8:52And we've seen even small language changes
- 8:55have quite passionate folks,
- 8:58I guess we should say.
- 9:00So yeah, yeah, very nice.
- 9:02Do you have any examples of the types of changes
- 9:04that y'all have,
- 9:05that have happened over the years
- 9:06that maybe were typing council only?
- 9:09One was the specification
- 9:09where how overloads work,
- 9:11which is perhaps not really a small change,
- 9:14but one of the most complicated features
- 9:16in the type system really is the overloads,
- 9:17where you can give multiple signatures
- 9:19for a function
- 9:20and type checkers sort of select
- 9:22which one to use based on the arguments
- 9:25when the function is called.
- 9:26And when it was initially created,
- 9:28from what I recall,
- 9:29there just wasn't really a specification.
- 9:31It's just like you use the signatures
- 9:33in a way that makes sense.
- 9:35And Eric Traut,
- 9:36who's currently on the council,
- 9:37came up with a pretty specific procedure
- 9:40for exactly how overload should work
- 9:42to make it so that type checkers have,
- 9:45well, sort of users can understand how it works
- 9:46and sort of type checkers can have something
- 9:47to work towards to make sure
- 9:49that they work infinite overloads in the same way.
- 9:51Maybe a smaller example
- 9:52that is an example of something
- 9:54that would have been too small for a pep
- 9:56and hard to accomplish
- 9:57before the typing council existed.
- 10:00And this is actually a change
- 10:01that I pushed through before the,
- 10:04before I was on the typing council,
- 10:05but the typing council approved it,
- 10:07was a clarification around
- 10:08the interpretation of data class fields.
- 10:11If a final annotation is applied
- 10:13to a data class field,
- 10:15does that mean,
- 10:16so if you apply a final annotation
- 10:18to a regular class attribute,
- 10:20since it can't be changed,
- 10:22that implies that it's a class variable.
- 10:24And there was a question of
- 10:25if that should be the interpretation
- 10:26with the data class or not.
- 10:28So we discussed that
- 10:29and made a clarification to the spec.
- 10:31I've never really thought about final
- 10:32being applied to a class field,
- 10:35but I've always used them
- 10:36sort of just for constants.
- 10:38But, you know,
- 10:38maybe people out there don't know,
- 10:40like typing dot final bracket type,
- 10:43right?
- 10:44That's kind of the way
- 10:45you can do constants in Python, right?
- 10:47Constants for the type checker.
- 10:48Nothing in the runtime
- 10:49will stop you from editing it.
- 10:51That's...
- 10:51Not there.
- 10:52Not there.
- 10:52I have some examples coming up
- 10:54and I'm interested
- 10:55to hear your thoughts on it,
- 10:56but for sure it's,
- 10:58there is this tension, right?
- 11:00I mean, I think that's probably
- 11:01worth touching on as well
- 11:02is this is a tension for Python
- 11:04in general is
- 11:05you can write all the types you want
- 11:07and then when you run your code,
- 11:09it just doesn't care.
- 11:11There's a few instances,
- 11:12Pydantic, FastAPI,
- 11:14a few others,
- 11:14but generally speaking,
- 11:15it's there for the editors
- 11:17and the type checkers
- 11:18and the linters
- 11:18and not for runtime, right?
- 11:20Yeah, that's right.
- 11:21There's many exceptions to that.
- 11:23There's a product like mypyc,
- 11:25which comes with mypy
- 11:26that's used those types
- 11:27to compile your code
- 11:28into more efficient machine codes.
- 11:30Maybe there's going to be
- 11:31more products like that
- 11:32in the future.
- 11:32I don't know.
- 11:33But yes, in general,
- 11:34it's separate from the runtime.
- 11:36Sort of a similar
- 11:37model to TypeScript
- 11:38where TypeScript
- 11:39gets compiled into JavaScript
- 11:40and types just go away.
- 11:42Here, we don't do
- 11:43a compilation step,
- 11:44but still the same idea
- 11:45of the types
- 11:45just not influencing the runtime.
- 11:47Although we do make them
- 11:48available for introspection
- 11:49via done annotations attributes,
- 11:51which is what has enabled
- 11:52the projects like Pydantic
- 11:54and other sort of
- 11:55runtime checkers
- 11:56to make use of type annotations
- 11:58at runtime also.
- 11:59Yeah, I don't know
- 12:00if the typing council
- 12:01was around for this,
- 12:02but there was proposed,
- 12:03I don't remember
- 12:03the exact details,
- 12:04but something to the effect
- 12:05of for type checking,
- 12:07not actually doing
- 12:08some of the full imports
- 12:11or something along those lines,
- 12:13right,
- 12:13where the runtime behavior
- 12:15would have made it hard
- 12:15for tools like Pydantic
- 12:17and others to get that.
- 12:19And there was
- 12:20some kind of compromise,
- 12:21right?
- 12:21I don't remember the details here.
- 12:22Anyone does?
- 12:23Yeah, what happened was
- 12:23that there was going
- 12:24to be a change.
- 12:25That's what the
- 12:26from future import
- 12:26annotations import does,
- 12:28that changes all annotations
- 12:29into raw strings.
- 12:30So the default behavior
- 12:32before recently
- 12:34was that annotations
- 12:35that are regular codes.
- 12:36If you write devf
- 12:37return to ints
- 12:38and you import the module,
- 12:39it just looks up
- 12:40the name ints
- 12:41and puts that
- 12:41in an annotations dictionary,
- 12:43which makes introspection easy,
- 12:44but it made
- 12:45a test on costs
- 12:47on performance
- 12:48because memory usage
- 12:49sometimes was high
- 12:50and also made things
- 12:51harder to use sometimes
- 12:52because if you use a name
- 12:54that's not defined yet
- 12:55at runtime,
- 12:56you get an error.
- 12:57That often comes up
- 12:58if you have like a class
- 12:59that has a reference
- 13:00in an adaptation
- 13:01to the class itself
- 13:02or circular
- 13:03dependency classes.
- 13:05Right.
- 13:06The circular imports
- 13:07because you want to say
- 13:08this class
- 13:09is created by that thing
- 13:11and it returns one,
- 13:12but you know,
- 13:13somehow you've got
- 13:15to import the other one
- 13:15and that's such a hassle.
- 13:17Yeah, it's,
- 13:18yeah, even out
- 13:18in the audience we have,
- 13:20Tom says,
- 13:20circular imports.
- 13:21Oh, yeah, for sure.
- 13:22What about lazy imports?
- 13:24Like that just recently
- 13:25got accepted
- 13:26and will be in 3.15.
- 13:27Which I'm super excited about
- 13:29because I think
- 13:29it'll make app startup
- 13:31a lot faster
- 13:32for many use cases.
- 13:34But does that have
- 13:35knock-on effects
- 13:35for typing?
- 13:36Not that directly
- 13:37because I think
- 13:39for a type checker
- 13:39lazy imports
- 13:40mostly just look
- 13:41like regular imports.
- 13:42I guess I should
- 13:43maybe leave that
- 13:43for the people
- 13:44who are actually
- 13:44working on type checkers
- 13:46and being written right now.
- 13:47Yeah, Rebecca,
- 13:47do you see this
- 13:48making any difference
- 13:49for you?
- 13:50Lazy imports?
- 13:51To be honest,
- 13:52it's not something
- 13:53we've looked at
- 13:54too carefully yet.
- 13:553.15
- 13:56seems a little
- 13:57more in the future,
- 13:59but I don't think
- 14:01it's likely
- 14:02to make a huge difference.
- 14:03Carl?
- 14:04I've thought about it briefly
- 14:05and I think that it,
- 14:06I think the type checkers
- 14:07really won't need to care.
- 14:08Maybe there will be
- 14:09some edge cases
- 14:10that will come up
- 14:10that I haven't thought of,
- 14:11but it shouldn't be a big deal.
- 14:12Yeah, that's what I thought
- 14:13as well.
- 14:14The one variation
- 14:15that I can certainly see
- 14:17is if you have a,
- 14:19if you have something
- 14:20specified in a type,
- 14:21like say for a field
- 14:23of a class
- 14:24or a Pydantic model
- 14:25or something
- 14:25that would otherwise
- 14:26not trigger
- 14:27the lazy import
- 14:28to become imported,
- 14:30would potentially
- 14:31having types specify
- 14:33cause more importing
- 14:34to happen sooner
- 14:36in the runtime?
- 14:36Yeah, there's actually
- 14:37an issue related to this
- 14:38that I think we may need
- 14:39to resolve before 3.15,
- 14:41but I don't know how yet.
- 14:43If you use a type
- 14:44in a data class annotation
- 14:45that's lazy imported,
- 14:46actually creating
- 14:47a data class
- 14:47will delay
- 14:48by the import.
- 14:49It will try to
- 14:50resolve the import
- 14:52and actually make it
- 14:54not lazy.
- 14:55This is because
- 14:55data classes
- 14:56doesn't really need
- 14:57to look at all
- 14:58of the annotations
- 14:58in your class,
- 14:59but it looks at them
- 15:00enough to trigger
- 15:01reification of the import.
- 15:04I shared this
- 15:04with some of the people
- 15:05on the lazy imports team,
- 15:06but we haven't
- 15:07yet come up
- 15:08with a good way around it.
- 15:09I think this might
- 15:09end up being
- 15:10a bit of a food gun,
- 15:11so I feel like
- 15:12we should ideally
- 15:12find a workaround,
- 15:14but I don't know
- 15:14what it would be yet.
- 15:15I don't know
- 15:15that it's wrong
- 15:16that it converts it
- 15:17to an eager import,
- 15:18which it needs
- 15:20to know what it is
- 15:20potentially,
- 15:21right?
- 15:22It actually doesn't.
- 15:24Data classes
- 15:24just need to know
- 15:25whether it is classed
- 15:26for or not.
- 15:27I think that's
- 15:27pretty much all.
- 15:28I guess there's
- 15:28an init for also,
- 15:29but it doesn't really
- 15:30need to know
- 15:31anything else.
- 15:32So in theory,
- 15:33it should be possible
- 15:33to just say,
- 15:34hey, it is not classed
- 15:35for, so don't bother
- 15:37importing it.
- 15:38Okay, so that's
- 15:39for data classes,
- 15:39but say if I specify
- 15:41a parameter type
- 15:42on a function.
- 15:43Yeah, then it
- 15:43should be fine.
- 15:45I guess, again,
- 15:46unless something is,
- 15:47if it does annotate,
- 15:48so if you have
- 15:49something like
- 15:49a decorator
- 15:50that looks at
- 15:50annotations in your
- 15:51function,
- 15:52it might reify
- 15:53those imports.
- 15:54There is one other
- 15:55potentially interesting
- 15:56thing for type checkers.
- 15:57It's already
- 15:58difficult for type checkers
- 15:59to figure out
- 16:00when like a submodule
- 16:02should be considered
- 16:03to be an attribute
- 16:04of the parent module
- 16:05because the way
- 16:06this happens in Python
- 16:07is that any import
- 16:08of a submodule
- 16:09anywhere will attach
- 16:10that submodule
- 16:11as an attribute
- 16:12on the parent module,
- 16:13but that at runtime,
- 16:15that could literally
- 16:16happen anywhere.
- 16:17It could happen
- 16:17in totally unrelated
- 16:18code outside of the module
- 16:19and a type checker
- 16:20probably won't be able
- 16:21to see that.
- 16:22So type checkers
- 16:22already have sort of
- 16:23complex sets of rules
- 16:24around where they look
- 16:26for these submodule
- 16:27imports and when they
- 16:27consider a submodule
- 16:28import to be reliably
- 16:30happening enough
- 16:31that it should,
- 16:32that the type checker
- 16:33should consider
- 16:34this submodule
- 16:35to exist as an attribute.
- 16:38And lazy imports
- 16:38may make that even,
- 16:40we'll add one more
- 16:41wrinkle
- 16:41to those
- 16:43sets of heuristics
- 16:44in that we'll have
- 16:44to decide
- 16:45if you have
- 16:46a lazy import
- 16:46of a submodule
- 16:47and you're done
- 16:47to init.py,
- 16:48it's lazy.
- 16:50So should the type checker
- 16:51consider that submodule
- 16:53to be imported
- 16:54or not be imported?
- 16:55It'll be another case
- 16:57where there's no
- 16:57clear right answer
- 16:58and we'll just have
- 16:58to make a decision
- 17:00one way or the other.
- 17:02This portion of
- 17:03Talk Python is brought
- 17:04to you by Sentry.
- 17:05I've been using
- 17:05Sentry personally
- 17:06on almost every
- 17:07application and API
- 17:09that I've built
- 17:10for Talk Python
- 17:10and beyond
- 17:11over the last few years.
- 17:13They're a core
- 17:13building block
- 17:14for keeping
- 17:14my infrastructure
- 17:15solid.
- 17:16They should be
- 17:17for yours as well.
- 17:18Here's why.
- 17:19Sentry doesn't
- 17:20just catch errors.
- 17:21It catches all
- 17:21the stuff
- 17:22that makes your
- 17:22app feel broken.
- 17:23The random slowdown,
- 17:25the freeze you
- 17:25can't reproduce,
- 17:26that bug that
- 17:27only shows up
- 17:28once real users
- 17:29hit it.
- 17:29And when something
- 17:30goes wrong,
- 17:30Sentry gives you
- 17:31the whole chain
- 17:32of events
- 17:32in one place.
- 17:33Errors,
- 17:33traces,
- 17:34replays,
- 17:35logs,
- 17:35dots connected.
- 17:36You can see
- 17:37what's led to
- 17:38the issue
- 17:38without digging
- 17:39through five
- 17:39different dashboards.
- 17:41Seer,
- 17:42Sentry's AI
- 17:42debugging agents
- 17:43builds on this
- 17:44data,
- 17:44taking the full
- 17:45context,
- 17:46explaining why
- 17:47the issue
- 17:48happened,
- 17:49pointing to
- 17:49the code
- 17:50responsible,
- 17:50drafts a fix,
- 17:51and even flags
- 17:52if your PR
- 17:52is about to
- 17:53introduce a new
- 17:54problem.
- 17:55The workflow
- 17:55stays simple.
- 17:56Something breaks,
- 17:57Sentry alerts you,
- 17:58the dashboard
- 17:59shows you
- 17:59the full context,
- 18:01Seer helps you
- 18:01fix it and
- 18:02catch new issues
- 18:03before they ship.
- 18:04It's totally
- 18:05reasonable to go
- 18:06from an error
- 18:07occurred to
- 18:07fixed in production
- 18:08in just 10 minutes.
- 18:10I truly
- 18:11appreciate the
- 18:11support that
- 18:12Sentry has
- 18:12given me to
- 18:13help solve my
- 18:14bugs and issues
- 18:15in my apps,
- 18:16especially those
- 18:17tricky ones that
- 18:18only appear in
- 18:19production.
- 18:19I know you will
- 18:20too if you try
- 18:21them out.
- 18:21So get started
- 18:22today with
- 18:23Sentry.
- 18:23Just visit
- 18:23talkpython.fm
- 18:24slash Sentry
- 18:25and get $100
- 18:27in Sentry credits.
- 18:28Please use that
- 18:29link.
- 18:29It's in your
- 18:30podcast player
- 18:30show notes.
- 18:31If you're
- 18:31signing up
- 18:31some other
- 18:32way,
- 18:32you can use
- 18:33our code
- 18:33talkpython26,
- 18:35all one word,
- 18:36talkpython26,
- 18:37to get $100
- 18:38in credits.
- 18:40Thank you to
- 18:40Sentry for
- 18:41supporting the
- 18:41show.
- 18:43Yeah, there's
- 18:43some variations
- 18:44across type
- 18:45checkers, which
- 18:45we'll get to
- 18:46later.
- 18:47I think,
- 18:48though, before
- 18:48we move off
- 18:49this, there's
- 18:50actually off
- 18:51introducing the
- 18:52typing council.
- 18:53I think we
- 18:54should point out
- 18:54that there's two
- 18:55other folks who
- 18:56couldn't be here
- 18:56who are also on
- 18:58the typing
- 18:58council, Eric
- 18:59Traut and
- 19:00Jukka
- 19:02Lehtosalo?
- 19:03Sorry,
- 19:04Yuka.
- 19:05But I want to
- 19:06make sure that
- 19:06we point out
- 19:07there's actually
- 19:07five people,
- 19:08not just the
- 19:08three of you,
- 19:09right?
- 19:09How do you
- 19:10get on the
- 19:10council?
- 19:11Is there an
- 19:12election?
- 19:13Do you just
- 19:13apply?
- 19:14I think these
- 19:15are filled by
- 19:15the members
- 19:16themselves.
- 19:16So when
- 19:17somebody declares
- 19:17the intention
- 19:18to leave the
- 19:19council, we
- 19:20basically ask for
- 19:20people who are
- 19:21interested and
- 19:22then make a
- 19:22selection.
- 19:23Generally, we
- 19:23try to get
- 19:24people who have
- 19:25experience in the
- 19:26type system.
- 19:27We try to get a
- 19:27good cross
- 19:28representation of
- 19:28people working
- 19:29on different
- 19:29type checkers.
- 19:30We have Carl
- 19:32and Rebecca
- 19:32here who work
- 19:33on two type
- 19:34checkers,
- 19:34TY and
- 19:35Pyrefly.
- 19:36Jukka works
- 19:36on Pyright's,
- 19:39which are two
- 19:39of the most
- 19:39lightly used
- 19:40type checkers.
- 19:41So we try to
- 19:42get representation
- 19:43of people working
- 19:44on those parts
- 19:45of the ecosystem.
- 19:46That's really
- 19:46cool that it's
- 19:47got a bias
- 19:48towards finding
- 19:48people actually
- 19:49doing the work.
- 19:50So let's talk
- 19:51about the
- 19:52specification project
- 19:53at typing.python.org.
- 19:55What is this
- 19:56here?
- 19:56I'll talk a bit
- 19:57about it.
- 19:58I guess it's
- 19:59a specification
- 20:00for how the
- 20:01type system
- 20:02used to work.
- 20:03The way it
- 20:04started was
- 20:05that, Jelle,
- 20:05you basically
- 20:06took all the
- 20:07typing peps
- 20:07and like
- 20:08stapled them
- 20:09together,
- 20:09right, to
- 20:10make like
- 20:11one long
- 20:11doc.
- 20:12And since
- 20:13then, we've
- 20:13been iterating
- 20:14on it,
- 20:15filling in
- 20:15parts that
- 20:16were missing
- 20:16like overload
- 20:18evaluation and
- 20:19making other
- 20:20changes as
- 20:21well.
- 20:21Yeah, it's
- 20:22tricky, right?
- 20:22Because
- 20:23traditionally, the
- 20:24typing system
- 20:25is kind of
- 20:26defined across
- 20:27a series of
- 20:28peps.
- 20:28And so what
- 20:29is the document
- 20:30that tells you
- 20:30how it works,
- 20:31right?
- 20:31Yeah, that
- 20:31made it hard
- 20:32because often
- 20:32there's peps
- 20:33built on top
- 20:34of each other.
- 20:35So then in
- 20:36the extreme,
- 20:37you might see
- 20:37like one thing
- 20:38in one pep
- 20:39and then there's
- 20:39another pep
- 20:40that adds
- 20:40an aspect of
- 20:41it, another
- 20:41one that adds
- 20:41another aspect.
- 20:43And overall
- 20:43it makes it
- 20:43very hard to
- 20:44follow.
- 20:44One of the
- 20:45things I did
- 20:45recently was
- 20:46rewrite the
- 20:47typed dict
- 20:54another.
- 20:55Ended up
- 20:55rewriting the
- 20:56whole thing
- 20:56to basically
- 20:57put all those
- 20:58features together
- 20:58in a coherent
- 20:59whole rather than
- 21:00just having them
- 21:02all copy-pasted
- 21:03one after the
- 21:04other.
- 21:04Okay, so if
- 21:05somebody really
- 21:05wants a good
- 21:06understanding of
- 21:07the Python
- 21:08typing system,
- 21:09they go to
- 21:09typing.python.org.
- 21:11You know, one
- 21:12thing I think
- 21:12maybe is worth
- 21:13touching on,
- 21:13it's just kind
- 21:14of out of the
- 21:15blue a bit,
- 21:16but I think
- 21:16it's a really
- 21:17interesting aspect
- 21:17of the Python
- 21:19typing system
- 21:20is the,
- 21:21what is it
- 21:21called, the
- 21:21numerical tower
- 21:22or the number
- 21:23tower, where
- 21:24it's like, if
- 21:25I have a
- 21:25number, I
- 21:26could specify
- 21:27it as an
- 21:27int, or I
- 21:28could specify
- 21:29it as a
- 21:29float, and
- 21:30those kinds
- 21:31of things, but
- 21:32do you really
- 21:33need to say
- 21:34it's an
- 21:34int pipe
- 21:35float, or a
- 21:36union of
- 21:37int and
- 21:37float, if it
- 21:38could be
- 21:38either, right?
- 21:39And the, what
- 21:40is it called?
- 21:40It's the
- 21:40numerical tower,
- 21:41right?
- 21:42Yeah, there
- 21:42are different
- 21:42towers too.
- 21:43In Python, there's
- 21:44also this thing
- 21:45called a numbers
- 21:45module that you
- 21:46have there, that's
- 21:48just basically
- 21:48ignored by the
- 21:49type system.
- 21:50It's been
- 21:50useful for some
- 21:51people, I feel
- 21:51like in general
- 21:52that module just
- 21:52hasn't worked out
- 21:53very well as
- 21:54being very
- 21:54useful.
- 21:55I think the
- 21:55interesting aspect
- 21:56is that you
- 21:58know, that you
- 21:58can say it's a
- 21:59float, and that's
- 22:00basically equivalent
- 22:01to union of
- 22:02integer and
- 22:03float, and so
- 22:04on, right?
- 22:05I think the
- 22:05typing numbers in
- 22:07Python is pretty
- 22:08interesting.
- 22:08I think every
- 22:09type checker has
- 22:10a different
- 22:11interpretation of
- 22:12what a float
- 22:13annotation actually
- 22:14means.
- 22:16It's an area of
- 22:17some lack of
- 22:18clarity in the
- 22:18spec.
- 22:19Yeah, a lot of
- 22:19contentiousness.
- 22:20If we could go
- 22:21back in time, I
- 22:22would, like,
- 22:23knowing what I
- 22:24know now, I
- 22:24probably advocate
- 22:25for things being
- 22:26done differently
- 22:27because, like,
- 22:28beginning, you
- 22:29know, like, there
- 22:30were multiple
- 22:31things, like, with
- 22:32similar flavor.
- 22:33Like, there was
- 22:34also one where
- 22:35you could give
- 22:36a parameter a
- 22:37non-none
- 22:38annotation and
- 22:39default it to
- 22:40none for
- 22:40convenience, and
- 22:41we've largely,
- 22:42like, moved away
- 22:43from stuff like
- 22:44that in favor of
- 22:44explicitness.
- 22:46Yeah, what the
- 22:46current spec says
- 22:47is that basically
- 22:48if you have a
- 22:48function that takes
- 22:49a float, you're
- 22:50also allowed to
- 22:51pass an int.
- 22:52That's not
- 22:53really enough.
- 22:54It doesn't tell
- 22:54you how these
- 22:55things work in
- 22:56all cases, and
- 22:57we've had some
- 22:59attempts to try to
- 23:00come up with a
- 23:01way to specify
- 23:02that special case
- 23:03in a way that
- 23:04makes more sense,
- 23:05at least makes
- 23:06more sense to me.
- 23:07It's been very
- 23:07contentious.
- 23:08People have very
- 23:09strong opinions
- 23:09about this.
- 23:10I guess non-obvious
- 23:11is what I'd like to
- 23:12say, really,
- 23:12honestly.
- 23:13So I'd like to get
- 23:15the official
- 23:16counsel's thoughts
- 23:17on this.
- 23:17When is typing
- 23:18too much typing?
- 23:20I made the joke
- 23:21about C++,
- 23:22ATL, if you've
- 23:23ever worked with
- 23:24that, it's like
- 23:24a template class
- 23:27where templated
- 23:28classes are part
- 23:28of the concrete
- 23:29type of the
- 23:30template.
- 23:30It's just off
- 23:31the hook.
- 23:32There's certainly
- 23:32places where
- 23:33typing can be
- 23:34too much, and
- 23:36a lot of the
- 23:37purity of Python
- 23:38or the readability
- 23:40of Python is the
- 23:41fact that it's
- 23:42got so few
- 23:43symbols.
- 23:44And so adding
- 23:44types adds
- 23:45context, but it
- 23:46also makes it
- 23:47a little harder
- 23:48to read.
- 23:49When is too
- 23:49much typing?
- 23:50When do you
- 23:51recommend typing?
- 23:53Rebecca, I'll
- 23:54let you go first,
- 23:54but what are your
- 23:55thoughts on how
- 23:57much typing should
- 23:57I use in Python?
- 23:59I'll give you
- 24:00what is my
- 24:01official stance,
- 24:03which is that if
- 24:03you want your
- 24:04type checker to
- 24:05work well, you
- 24:06should type
- 24:07annotate your
- 24:08API boundaries.
- 24:09So parameters
- 24:10and turns in
- 24:11public functions,
- 24:12public class
- 24:12attributes, things
- 24:14like that, and
- 24:14even things that
- 24:15seem true
- 24:16trivial, like,
- 24:17oh, this
- 24:17function returns
- 24:18none, better
- 24:20to annotate
- 24:21it because, you
- 24:22know, someone
- 24:22else might be
- 24:23depending on
- 24:24your library and
- 24:25consuming that
- 24:25type of
- 24:26information.
- 24:27I will say
- 24:27personally, what
- 24:29I tend to do
- 24:29is I annotate
- 24:31things that I
- 24:32think are
- 24:32non-trivial
- 24:33because I want
- 24:34to see that
- 24:35as documentation.
- 24:37And if
- 24:38something, you
- 24:39know, a
- 24:39function that
- 24:39does return
- 24:40none, to be
- 24:41honest, I will
- 24:42probably forget
- 24:42to annotate it
- 24:43half the time
- 24:44because I'll
- 24:45be like, I
- 24:46honestly don't
- 24:46need to see
- 24:47it.
- 24:47One of the
- 24:48interesting features
- 24:49of the
- 24:50Pyrefly VS
- 24:52Code extension,
- 24:53that's the only
- 24:53one I can speak
- 24:54of at the
- 24:54moment, and
- 24:55Carl, you've
- 24:55got to tell
- 24:56me if the
- 24:56TY one does
- 24:58this as well,
- 24:59is it will
- 24:59sort of overlay
- 25:00its belief of
- 25:02what types
- 25:03are.
- 25:03Like, if
- 25:04there's, you
- 25:05say x equals a
- 25:06function return
- 25:06value and it
- 25:07knows what the
- 25:07function returns,
- 25:08it'll have a
- 25:08gray, like,
- 25:09colon int, if
- 25:10it returned an
- 25:11int or something.
- 25:11So you can
- 25:12kind of read
- 25:14the code and
- 25:15see what the
- 25:15types are without
- 25:16actually putting
- 25:17it into the
- 25:18text of the
- 25:18code.
- 25:19It's only within
- 25:19the editor.
- 25:20Does ty do
- 25:21something like
- 25:21that, Carl?
- 25:22Yes, we also
- 25:22have inlay type
- 25:23ins.
- 25:23Yeah, inlay type
- 25:24ins, that's
- 25:24what it's called.
- 25:25So, yeah, I
- 25:26don't know, that
- 25:26also brings an
- 25:27interesting challenge,
- 25:28not a challenge,
- 25:28like a wrinkle to
- 25:30the recommendation
- 25:31of should I put
- 25:33types on, like,
- 25:34the return value
- 25:35because I want to
- 25:35know that's a
- 25:36list of user,
- 25:37not a list of
- 25:37user IDs or
- 25:38whatever, for
- 25:39example, like a
- 25:39list of UUID.
- 25:41But if,
- 25:41it's going to
- 25:42show up anyway
- 25:43in the editor,
- 25:44maybe I don't
- 25:44have to write
- 25:45that, right?
- 25:45And so that
- 25:46becomes sort of
- 25:47somewhere where
- 25:48you could debate
- 25:49again, I think.
- 25:50However, I do
- 25:51100% agree with
- 25:52you, Rebecca, that
- 25:53put it on your
- 25:53API boundaries.
- 25:54If, like, this
- 25:55is the place that
- 25:56people get into
- 25:57some part of your
- 25:58code and they
- 25:58don't know or
- 25:59want to know about
- 26:00the inside of it,
- 26:01having types there
- 26:02is really helpful
- 26:03both for editors,
- 26:04for type checkers,
- 26:05and just for
- 26:06reading code, and
- 26:07even for AI, which
- 26:08is a crazy world.
- 26:09Yeah.
- 26:09Carl?
- 26:10What are your
- 26:11thoughts here?
- 26:11How much typing is
- 26:12too much typing?
- 26:13What's the
- 26:13guidelines here?
- 26:14I think I agree
- 26:15with Rebecca's
- 26:15answer.
- 26:16I mean, that one
- 26:17place you definitely
- 26:17want to have
- 26:18explicit type
- 26:19annotations is that
- 26:21API boundaries,
- 26:22the public API of
- 26:23a library, etc.
- 26:24In terms of what's
- 26:25too much typing, I
- 26:26mean, there are
- 26:27certainly patterns
- 26:28that have
- 26:28historically been
- 26:29used in Python
- 26:31that we still
- 26:32can't express well
- 26:34in the type
- 26:34system, or that
- 26:35require extremely
- 26:36complex type
- 26:37annotations to
- 26:39express well, and
- 26:40I think there it
- 26:40becomes a judgment
- 26:41call.
- 26:43If it's like a
- 26:44core, widely
- 26:45used API, you
- 26:46may get a lot of
- 26:47benefit from some
- 26:48very complex and
- 26:50verbose annotations,
- 26:51and so then it's
- 26:52worth sort of going
- 26:53through that pain
- 26:53and the pain of
- 26:55adding them and
- 26:55of reading them in
- 26:56order to get that
- 26:57additional typing
- 26:59coverage everywhere you
- 27:00use that API.
- 27:01If it's much less
- 27:02frequently used code
- 27:03that's highly dynamic,
- 27:04maybe it's not worth
- 27:05it in that case.
- 27:06I think there's a lot
- 27:07of judgment calls
- 27:07here.
- 27:08What about like
- 27:08one-off scripts?
- 27:10You know, I'm going
- 27:11to write this thing to
- 27:11just move this data
- 27:12from here to there,
- 27:13and once it's moved,
- 27:14I don't need it again.
- 27:15It's done with that
- 27:16old system, we're
- 27:16going to the new
- 27:17one.
- 27:17Maybe less typing.
- 27:18Yeah, I think
- 27:19that's what's useful
- 27:20for you.
- 27:20Often I feel like
- 27:21one-off scripts are
- 27:22not really one-off
- 27:23like maybe you
- 27:23want to move some
- 27:24similar data later,
- 27:25and then it's useful
- 27:26if you can understand
- 27:27your code again,
- 27:27if you want to
- 27:29read what you did.
- 27:29You thought you
- 27:30didn't need it again,
- 27:30and all of a sudden
- 27:31at six months old,
- 27:32you don't understand
- 27:33it, and the types
- 27:34that help a lot,
- 27:35right?
- 27:35Yeah.
- 27:36Yellow, what's
- 27:36your advice?
- 27:38What Carl and
- 27:39Rebecca said
- 27:39makes sense to me
- 27:40too.
- 27:40I think types
- 27:41have advantages
- 27:42in terms of
- 27:43documenting humor
- 27:44readers, what
- 27:45is going on,
- 27:46and in terms of
- 27:47catching mistakes
- 27:47that otherwise
- 27:48would not be
- 27:49caught until
- 27:49runtime perhaps.
- 27:51They have costs
- 27:51in maybe making
- 27:52your code harder
- 27:52to read if
- 27:53there's too much
- 27:54going on.
- 27:54So add types
- 27:55as long as
- 27:56those benefits
- 27:56outweigh the
- 27:57costs.
- 27:57Yeah.
- 27:58I mean, do you
- 27:59recommend to
- 27:59anyone that they
- 28:01just 100% go full
- 28:03like C++,
- 28:04C# on it,
- 28:05and just type it
- 28:06every single thing?
- 28:08Is there an
- 28:08advantage like for
- 28:10static type checkers,
- 28:11you know, like
- 28:11mypy type stuff
- 28:12you can run across
- 28:13and get that?
- 28:14I mean, you could
- 28:15do that with
- 28:15Pyrefly or TY
- 28:16and the CLI as
- 28:17well, but you know,
- 28:18thinking more mypy
- 28:19is like kind of
- 28:19being real strict
- 28:20on some of that
- 28:21stuff.
- 28:21Personally, I do
- 28:22tend to annotate
- 28:23almost all like
- 28:23function parameters
- 28:24and if class
- 28:26attributes, if I
- 28:27make a class,
- 28:28sometimes it's not
- 28:28as necessary,
- 28:29like you don't
- 28:30really need to
- 28:30annotate your
- 28:31tests perhaps,
- 28:32or you don't
- 28:32need to annotate
- 28:33internal functions
- 28:33as much, but
- 28:34for my own
- 28:35coding, I usually
- 28:36find it helpful
- 28:36to do that.
- 28:37But sometimes I
- 28:39see people
- 28:39annotating even
- 28:40local variables
- 28:41where it's very
- 28:41obvious to type
- 28:42check if the type
- 28:43is and they can
- 28:44just infer it
- 28:44reliably, and then
- 28:46it really just
- 28:46adds noise and
- 28:47you shouldn't do
- 28:48it.
- 28:48Yeah, exactly.
- 28:48If you've got a
- 28:49function that's
- 28:50annotated with a
- 28:50return value and
- 28:51you say x equals
- 28:53the function call,
- 28:54then the type
- 28:55checkers can infer
- 28:55that and you're
- 28:56just causing
- 28:57extra noise, I
- 28:59guess.
- 29:00So suppose you
- 29:01all want to
- 29:02change something.
- 29:03What's the process
- 29:04of actually going
- 29:05through and making
- 29:06some changes?
- 29:08Mostly sort of
- 29:09two levels of
- 29:09this.
- 29:10Well, maybe
- 29:10there's even
- 29:11three levels.
- 29:11The first one is
- 29:12if it's something
- 29:12that's so small
- 29:13that's just like
- 29:14a wording
- 29:15clarification or
- 29:15something, we
- 29:16just make a PR
- 29:17to the repo and
- 29:18a few of us
- 29:19look at it and
- 29:20we change it.
- 29:21The second level
- 29:21is when it's sort
- 29:22of a smaller
- 29:22change that
- 29:24doesn't really
- 29:25introduce a new
- 29:25feature and then
- 29:26we make a PR
- 29:28to the typing
- 29:28spec repo and
- 29:30we formally have
- 29:31all of us sign
- 29:31off on it.
- 29:32That's what
- 29:33happens like
- 29:34what Carl
- 29:34mentioned earlier
- 29:35of the final
- 29:35change in data
- 29:37classes.
- 29:37It's had to
- 29:38merge this one,
- 29:39yeah, add
- 29:40Carl.
- 29:41I love it.
- 29:42This repo itself
- 29:43doesn't have
- 29:44anything.
- 29:44It's the
- 29:45Python typing
- 29:46repo where the
- 29:47decisions are
- 29:48made.
- 29:48The typing
- 29:49council just
- 29:49has like some
- 29:50documentation.
- 29:52Yeah.
- 29:52And then the
- 29:53third level is
- 29:53peps, like really
- 29:54big new changes.
- 29:55You can still
- 29:56write a PEP and
- 29:56then we make a
- 29:57recommendation and
- 29:58the steering
- 29:59council makes a
- 29:59decision eventually.
- 30:00So if I wanted
- 30:01to suggest
- 30:01something, I
- 30:02could come up
- 30:03here and I
- 30:04could open up
- 30:05an issue, maybe
- 30:06start a conversation
- 30:07on typing,
- 30:09Python slash
- 30:09typing.
- 30:10And you can make
- 30:10a pull request
- 30:11to change the
- 30:11spec.
- 30:12Okay.
- 30:12And so the
- 30:13pull request
- 30:13would not be
- 30:14to change the
- 30:15code, like
- 30:16how Python
- 30:17maybe interprets
- 30:18code that has
- 30:19this new thing,
- 30:20but to suggest
- 30:21that the spec
- 30:22has it, which
- 30:22then would start
- 30:23a process that
- 30:24ultimately might
- 30:25make CPython
- 30:26understand it,
- 30:26right?
- 30:27Well, CPython
- 30:27itself probably
- 30:28doesn't do
- 30:29anything with it.
- 30:30I guess most of
- 30:30the things that
- 30:31go directly here
- 30:31are changes to
- 30:32how to interpret
- 30:33things that are
- 30:33already in CPython.
- 30:37This portion of
- 30:38Talk Python To Me
- 30:38is brought to you
- 30:39by us.
- 30:40I want to tell
- 30:41you about a
- 30:42course I put
- 30:42together that
- 30:43I'm really proud
- 30:44of, Agentic
- 30:45AI Programming
- 30:46for Python
- 30:46Developers.
- 30:48I know a lot
- 30:49of you have
- 30:49tried AI coding
- 30:50tools and come
- 30:51away thinking,
- 30:52well, this is
- 30:52more hassle
- 30:53than it's worth.
- 30:54And honestly,
- 30:55all the vibe
- 30:56coding hype
- 30:57isn't helping.
- 30:58It's a smokescreen
- 30:59that hides what
- 30:59these tools can
- 31:00actually do.
- 31:01This course is
- 31:02about agentic
- 31:03engineering,
- 31:04applying real
- 31:05software engineering
- 31:06practices with AI
- 31:07that understands
- 31:08your entire code
- 31:09database, runs
- 31:10your tests, and
- 31:11builds complete
- 31:12features under
- 31:13your direction.
- 31:14I've used these
- 31:14techniques to ship
- 31:15real production code
- 31:17across Talk Python,
- 31:18Python Bytes, and
- 31:19completely new
- 31:20projects.
- 31:21I migrated an
- 31:21entire CSS framework
- 31:22on a production
- 31:23site with thousands
- 31:24of lines of HTML
- 31:25in a few hours,
- 31:27twice.
- 31:28I shipped a new
- 31:29search feature with
- 31:30caching and async
- 31:31in under an hour.
- 31:32I built a complete
- 31:33CLI tool for
- 31:35Talk Python from
- 31:36scratch, tested,
- 31:38documented, and
- 31:38published to PyPI in
- 31:40an afternoon.
- 31:41Real projects, real
- 31:42production code, both
- 31:43Greenfield and
- 31:45legacy.
- 31:46No toy demos, no
- 31:47fluff.
- 31:48I'll show you the
- 31:48guardrails, the
- 31:49planning techniques, and
- 31:50the workflows that
- 31:51turn AI into a
- 31:53genuine engineering
- 31:53partner.
- 31:54Check it out at
- 31:55talkpython.fm
- 31:56slash agentic
- 31:57dash engineering.
- 31:58That's talkpython.fm
- 32:00slash agentic dash
- 32:01engineering.
- 32:01The link is in your
- 32:02podcast player's
- 32:03show notes.
- 32:05If it's adding
- 32:06something new, it
- 32:07will usually need to
- 32:08go through a path,
- 32:09except if it's
- 32:09something very small.
- 32:10Let's talk about
- 32:11that for a minute.
- 32:11We got two
- 32:13representatives here
- 32:14of the newer
- 32:15breed of tools.
- 32:17What's the story
- 32:18for inconsistencies
- 32:21across interpretations
- 32:22of the spec?
- 32:23I know that there's
- 32:24slight variations.
- 32:25I've also, you
- 32:26know, not putting
- 32:27either of you on
- 32:28the spotlight, but
- 32:29like using, say,
- 32:31PyCharm and
- 32:32like writing code.
- 32:33So it's type
- 32:34checkers happy and
- 32:35then using something
- 32:36like Pyright.
- 32:37And so it has a
- 32:39real different
- 32:39interpretation of
- 32:41what you should let
- 32:42slide and what you
- 32:42shouldn't.
- 32:43I feel like Pyright
- 32:43is more, much more
- 32:45focused on like
- 32:47enforcing the
- 32:48nullability and or
- 32:49the lack thereof.
- 32:50And it warns of
- 32:51inconsistencies there
- 32:52where PyCharm doesn't
- 32:53seem to care as much.
- 32:54I don't know which
- 32:55one I like better,
- 32:56but I know they're
- 32:56different.
- 32:57And if I write code
- 32:57in one that I
- 32:58open the other, I'm
- 32:59like, huh, why is it
- 33:00upset?
- 33:00It seemed like it
- 33:01was fine.
- 33:02How do you all
- 33:02navigate this?
- 33:03Yeah.
- 33:03One thing useful to
- 33:04say about the spec
- 33:05there is that the
- 33:06spec covers a lot of
- 33:07things.
- 33:08In particular, it
- 33:08tends to cover sort
- 33:09of the details of
- 33:10more advanced type
- 33:11system features.
- 33:12But there's a lot of
- 33:13very fundamental
- 33:14stuff about how a
- 33:16type checker works
- 33:17in terms of how it
- 33:18does inference and
- 33:19how it does type
- 33:20narrowing.
- 33:21And even in some
- 33:22cases, like you
- 33:23mentioned, you know,
- 33:23what it chooses to
- 33:24emit errors on that
- 33:25isn't really covered
- 33:27by the spec, partly
- 33:28maybe because we
- 33:29haven't gotten to
- 33:30it and also partly
- 33:31intentionally in that
- 33:33there may be room in
- 33:35some of those cases
- 33:35for different type
- 33:36checkers to work
- 33:37differently if they're
- 33:38serving different
- 33:38needs.
- 33:39Like if PyCharm is
- 33:40primarily concerned
- 33:41about being a
- 33:42useful kind of IDE
- 33:44and providing go-to
- 33:45definition and that
- 33:46sort of thing, maybe
- 33:47emitting lots of
- 33:48warnings or errors
- 33:50and all kinds of
- 33:51things where your
- 33:52code might be doing
- 33:52something wrong isn't
- 33:54as high a priority.
- 33:54And another type
- 33:56checker might have
- 33:56a different priority.
- 33:57One thing I do
- 33:58want to mention is
- 33:59that it may not
- 34:01seem like it, but
- 34:02things are already
- 34:04much better than
- 34:05they used to be.
- 34:07Like previously, I
- 34:08worked on a
- 34:09different type
- 34:09checker called
- 34:10PyType.
- 34:11And at that time,
- 34:12it was, you know,
- 34:13sort of the Wild
- 34:14West.
- 34:14Like we want to
- 34:15know how other
- 34:16type checkers like
- 34:17do something.
- 34:18Well, you know,
- 34:18like open up the
- 34:19mypy playground,
- 34:20open up the
- 34:21Pyright playground,
- 34:22see what tells
- 34:24you.
- 34:25Now we at least
- 34:25have spec and
- 34:26conformance tests.
- 34:28Yeah, that's
- 34:28really cool.
- 34:29How much would
- 34:29you say that
- 34:31your two type
- 34:32checkers maybe
- 34:34bring in mypy
- 34:35as well?
- 34:36Like how much
- 34:36do they agree
- 34:37versus disagree?
- 34:38You know, like
- 34:38you only see the
- 34:40differences.
- 34:40You don't see in
- 34:41which ways that
- 34:41they are the same
- 34:42as a consumer of
- 34:43them so much,
- 34:44right?
- 34:44You're like, why
- 34:45is this one
- 34:45squiggly when it
- 34:46wasn't squiggly
- 34:46before?
- 34:47But how similar
- 34:48or different are
- 34:49they?
- 34:49I don't know how
- 34:49we would quantify
- 34:50that.
- 34:51I think there's a
- 34:51lot that is the
- 34:52same just because
- 34:53it's based on how
- 34:54Python actually
- 34:55works.
- 34:56We're both trying
- 34:56to model the
- 34:57same language and
- 34:58then there's
- 34:58certainly also
- 34:59plenty of
- 34:59differences or
- 35:00things that we
- 35:01handle differently.
- 35:02So Rebecca, do you
- 35:02have a better way
- 35:03to quantify that?
- 35:04Yeah, I agree.
- 35:05it's hard to
- 35:06quantify, I suppose,
- 35:08talk a bit
- 35:08abstractly about
- 35:10various type
- 35:11checkers philosophies.
- 35:13With Pyrefly, we
- 35:14really try to do
- 35:15a lot of type
- 35:16inference.
- 35:17So that's a way
- 35:17in which we
- 35:18intentionally diverge
- 35:19a bit from mypy.
- 35:21But other than
- 35:22that deliberate
- 35:23decision, if we
- 35:24see ways in which
- 35:24we are accidentally
- 35:25different, we do
- 35:27try to fix that
- 35:28because otherwise
- 35:29people would have
- 35:30a hard time running
- 35:31multiple type
- 35:32checkers or
- 35:32migrating.
- 35:33Yeah, differences
- 35:33obviously cause
- 35:35pain for users
- 35:36who are using
- 35:37multiple type
- 35:37checkers or
- 35:38writing libraries
- 35:39that need to
- 35:39support multiple
- 35:40type checkers.
- 35:40So like Rebecca
- 35:41said, it's like if
- 35:43we are different
- 35:43from other type
- 35:44checkers, we want
- 35:45to be sure that
- 35:45there's a good
- 35:45reason for that
- 35:46difference.
- 35:47The difference
- 35:47should be because
- 35:49of philosophical
- 35:49choice, not just
- 35:51you happen to have
- 35:52chosen slightly
- 35:53differently, right?
- 35:54Yeah, and it's
- 35:54not just people who
- 35:56run different type
- 35:57checkers.
- 35:58Like you pointed
- 35:59out, Carl, a lot
- 36:00of times it is if I
- 36:01have a library and
- 36:02then different people
- 36:03want to consume
- 36:04that library, then
- 36:05their type checker
- 36:06may or may not
- 36:07warn them about how
- 36:08my library declares
- 36:09its types and so
- 36:10on.
- 36:11I'll give you a
- 36:12real quick example.
- 36:14I have a, I can't
- 36:16remember which one
- 36:17it was, I have
- 36:17three or four
- 36:17different open
- 36:19source libraries
- 36:19that I've created
- 36:20that somehow work
- 36:21with creating,
- 36:23basically passing
- 36:24data to templates
- 36:25in web apps,
- 36:27right?
- 36:27So one is like I
- 36:28want to use the
- 36:29Chameleon web
- 36:30template framework,
- 36:30but with fast
- 36:31API or with
- 36:32Flask or there's
- 36:33some other
- 36:33variations like
- 36:34partials and so
- 36:35on.
- 36:35I can't remember
- 36:36which one, but it
- 36:37doesn't really
- 36:37matter.
- 36:37One of them
- 36:38decorated a
- 36:39Flask.
- 36:40I think it was a
- 36:41Flask, especially
- 36:42makes it irrelevant.
- 36:43A Flask endpoint
- 36:44and Pyright was
- 36:46really upset.
- 36:47Like the error
- 36:48message filled the
- 36:49entire page of
- 36:50how it was
- 36:51inconsistent with
- 36:53what it expected
- 36:54for the definition
- 36:54of the Flask
- 36:55view method.
- 36:56I'm like, no one
- 36:57is going to call
- 36:58this.
- 36:58Like what does
- 36:58it even matter
- 36:59what this type
- 37:00is?
- 37:01It still runs
- 37:01fine.
- 37:02The runtime is
- 37:02fine.
- 37:03You know, it's no
- 37:04problem with this
- 37:05decorator.
- 37:05It worked fine, but
- 37:07something about the
- 37:08way that the Flask
- 37:10at get returned
- 37:11the type versus
- 37:12what my thing
- 37:13returned varied in
- 37:14like a really
- 37:15slight way.
- 37:16I didn't care, but
- 37:17somebody was using
- 37:18some editor that
- 37:19used Pyright and
- 37:20they're like, you
- 37:21have to help fix
- 37:22this.
- 37:22I can't take all
- 37:23these warnings.
- 37:23They're huge and
- 37:24they're everywhere.
- 37:25Like, okay, I'll
- 37:26go fix it.
- 37:27Right.
- 37:27And I went and I
- 37:29put way more effort
- 37:30than was justified
- 37:31into a function type
- 37:32that no one ever
- 37:33calls just to make
- 37:34the errors on some
- 37:36type checker I
- 37:37didn't use go
- 37:38away.
- 37:38Right.
- 37:39And that's the
- 37:39kind of thing where
- 37:40it becomes just a
- 37:41headache.
- 37:41I don't know.
- 37:42I wish I remember.
- 37:42I probably got that
- 37:43written down in an
- 37:44issue somebody filed,
- 37:46but it was, it was
- 37:46a gnarly error.
- 37:47And, or if you're
- 37:48working on an open
- 37:49source project, you
- 37:50know, you can't make
- 37:50everybody use the
- 37:51same editor that
- 37:53wants to contribute
- 37:53on a big project.
- 37:55And so you might run
- 37:55into this variation as
- 37:56well.
- 37:57So there's a lot
- 37:57of cases.
- 37:58Yeah.
- 37:58It can be really
- 37:58difficult to make
- 38:00these decisions about
- 38:01what kind of, what
- 38:03sorts of errors people
- 38:04want their type checker
- 38:06to catch or what's
- 38:07too pedantic.
- 38:08You want your type
- 38:09checker to catch
- 38:10non-obvious errors,
- 38:11not just the obvious
- 38:12ones that you probably
- 38:13would have seen by
- 38:14looking at the code
- 38:14yourself.
- 38:15But then there'll be
- 38:16cases where somebody
- 38:17says, well, I don't
- 38:18care.
- 38:18That's too pedantic.
- 38:19And it is difficult to
- 38:20make everyone happy.
- 38:21Who decides what the
- 38:22right signature of a
- 38:24flask view and point
- 38:25should be like if you
- 38:27the framework can call
- 38:27it.
- 38:28It should be okay.
- 38:29There's not.
- 38:30Just because it had a
- 38:30decorator before, that
- 38:31doesn't mean that's the
- 38:32official structure.
- 38:33But anyway, I do think
- 38:34one of the bigger
- 38:35philosophical differences
- 38:37has to do around this
- 38:39concept of nullability.
- 38:41Do you guys call it
- 38:42nullability or none
- 38:43ability?
- 38:44Like nullability comes
- 38:45from the other
- 38:46languages.
- 38:46And by that, I mean, I
- 38:48can specify that I have
- 38:49an integer.
- 38:49And in the Python type
- 38:51system, it cannot be set
- 38:53to none, even though in
- 38:54the runtime it can.
- 38:55It has to be a concrete
- 38:56int type unless you make
- 38:58it a optional int or an
- 39:00int pipe none or one of
- 39:02those type things, right?
- 39:03And how strong that gets
- 39:05enforced seems to be one
- 39:06of the biggest difference
- 39:07of opinions that I've
- 39:09seen around.
- 39:10Like, how do you all
- 39:10think about that?
- 39:11That's interesting to me
- 39:12that that's your
- 39:13experience because my
- 39:15experience has been that
- 39:16that's actually an area
- 39:16where everyone seems to
- 39:18agree as far as I can
- 39:19tell that these are is
- 39:21an important source of
- 39:22bugs and it's better to
- 39:22catch them.
- 39:23So I think all of the
- 39:24type checkers, maybe you
- 39:25said PyCharm doesn't.
- 39:26I don't think PyCharm
- 39:27does that.
- 39:28I'm pretty sure it
- 39:29doesn't because I agree
- 39:31that it's an important
- 39:32thing to check, but it's
- 39:34also a point of a lot of
- 39:35friction.
- 39:37And by that, I mean,
- 39:38let's suppose I'm going
- 39:39to have a class that I
- 39:41need to create an
- 39:42instance of and then put
- 39:43values into.
- 39:45And I know once I put
- 39:46the values into it, let's
- 39:47say it has a user ID, I
- 39:49know for certain that
- 39:50that's going to be an
- 39:51integer, right?
- 39:53So I'd like to say user
- 39:54ID colon int because
- 39:55everywhere I use that
- 39:57object later, if it's a
- 39:58function that takes an
- 39:59int and I specify it as
- 40:01optional int, I will get
- 40:03a type check warning
- 40:03every single call site
- 40:05when I try to pass that.
- 40:07But I know from the
- 40:08semantics of the
- 40:09behavior that it's going
- 40:10to always be an int
- 40:12unless it's not
- 40:13initialized, right?
- 40:14And like in this short
- 40:16period where I want to
- 40:17create it.
- 40:17So I can't set the type
- 40:18to int.
- 40:19I have to set the
- 40:19optional int until I've
- 40:20loaded it.
- 40:21And, but there's like
- 40:22this, I don't know,
- 40:23that's, that's the part
- 40:24where I see a lot of it
- 40:25show up is inconsistencies
- 40:27and then warnings all
- 40:29over the place.
- 40:29So I'm like, well, but
- 40:31that function is actually
- 40:32checking if it's none
- 40:33and it'll return null,
- 40:35you know, none or
- 40:35something like that.
- 40:36So I totally agree with
- 40:38you.
- 40:38It's just somewhere I've
- 40:39seen the most
- 40:40inconsistencies across
- 40:41maybe PyCharm versus
- 40:43others.
- 40:44mypy also has a legacy
- 40:45mode for not checking
- 40:46none things called
- 40:48non-strict optional.
- 40:50We're trying to get
- 40:51rid of that from mypy
- 40:52because yeah, strict
- 40:53optional, like being
- 40:54strict about it is the
- 40:55more sensible thing to
- 40:55do.
- 40:56But it's possible that
- 40:57you've seen that too.
- 40:59Yeah, I agree.
- 40:59So what you mentioned
- 41:00is maybe sort of a
- 41:01special case of the
- 41:02case where you pass
- 41:03something to a class
- 41:04and there's initialization
- 41:05that changes the types.
- 41:06Doesn't necessarily have
- 41:07to deal with none.
- 41:08It could also just be
- 41:08like the attribute doesn't
- 41:09exist at all beforehand
- 41:10or something.
- 41:11Yeah, we don't have a
- 41:12good solution for that.
- 41:13Maybe there's room for
- 41:14something to support that
- 41:16use case better.
- 41:17I don't know what it
- 41:17would look like.
- 41:18In some cases, there's
- 41:19ways you can, these
- 41:20things can sometimes
- 41:21nudge you towards a
- 41:22different design that is
- 41:23actually safer and will
- 41:24avoid errors.
- 41:26Like in the kind of
- 41:27case you're talking
- 41:27about, you know, is
- 41:29it actually necessary
- 41:30that an uninitialized
- 41:31object and an
- 41:32initialized one are
- 41:33represented by the
- 41:34same type?
- 41:34Or is there a way to
- 41:35adjust the API so that
- 41:37those are actually
- 41:37different types than you
- 41:38solve the problem and
- 41:40your code is safer
- 41:41or so?
- 41:41I'm thinking like you
- 41:42submit a web form and
- 41:44before you parse it, you've
- 41:45got to create the instance
- 41:46to set the values.
- 41:47And I don't know.
- 41:48It's not worth diving into,
- 41:49but I do find this
- 41:50differentiation between like
- 41:52the strict enforcement of
- 41:53none versus not none.
- 41:55I think it's powerful and I
- 41:56do think you all are right
- 41:57that it does catch a lot of
- 41:58errors.
- 41:58It's just, it's just a
- 42:00difference and it's just an
- 42:00interesting, interesting
- 42:02choice.
- 42:02But I didn't get a
- 42:03concrete answer from the
- 42:05official counsel.
- 42:06Nullable or
- 42:07noneable?
- 42:08What is it?
- 42:09I feel like you just
- 42:09don't really even talk
- 42:10about it as a term mostly.
- 42:12It's, yeah, none is
- 42:13special in the type system
- 42:15in like how you represent
- 42:16it, but it's not really
- 42:17special in other ways.
- 42:19You don't have a term for
- 42:20int pipe none?
- 42:22Int or none.
- 42:22Historically, the term was
- 42:23optional, although I think
- 42:24that term has problems and
- 42:26we're sort of moving away
- 42:28from it because
- 42:29specifically one problem is
- 42:31that optional can mean
- 42:33you don't have to pass it
- 42:34in, like I say, as a
- 42:36function parameter.
- 42:37Let's talk a little bit
- 42:38about TypeShed.
- 42:40I think TypeShed is pretty
- 42:41interesting.
- 42:41Maybe people don't know
- 42:42too much about it.
- 42:44So I'm sure you all are
- 42:45familiar with this project
- 42:47that you can basically add
- 42:48type information that the
- 42:50libraries didn't bother to
- 42:51include for you, right?
- 42:53What are thoughts on TypeShed?
- 42:54How much do you all lean on
- 42:55this to sort of round out
- 42:57missing types?
- 42:58There are two parts to
- 42:59TypeShed, right?
- 43:00There's the standard library
- 43:02type stubs, which I think
- 43:04are invaluable.
- 43:06Like all the type checkers
- 43:07use those.
- 43:08And I mean, will the standard
- 43:09library itself ever have
- 43:10inline types?
- 43:12Who knows?
- 43:12This might be around forever.
- 43:14And then there are also
- 43:15the third party stubs.
- 43:18And I think that's what you're
- 43:20describing.
- 43:20They're libraries that for
- 43:21whatever reason don't ship
- 43:23with stubs themselves.
- 43:24Those are in TypeShed.
- 43:26And I think it's been like
- 43:29for a while, there's sort of
- 43:31been a question of like what
- 43:31we want to do with like
- 43:33TypeShed's third party stubs,
- 43:35right?
- 43:35Because like ideally like
- 43:37libraries would ship with
- 43:38their own types, but there
- 43:39are various obstacles to that.
- 43:41The obstacles that I know of
- 43:43used to be like, we want this
- 43:45to run on Python 2 and Python 3.
- 43:47Or we want it to run on
- 43:48Python 3.3 still.
- 43:50But it's been a long time
- 43:52since any non-type supporting
- 43:55version of Python was a real,
- 43:57you know, a supported type
- 43:58of thing, right?
- 43:59I mean, even 3.9 became
- 44:01deprecated.
- 44:02So on one hand, I feel like
- 44:04they could be merged in,
- 44:05but there's also a lot of
- 44:07other areas that are maybe
- 44:09we don't, they're not common,
- 44:12right?
- 44:12Like other libraries, like
- 44:13pick some, let's say Pyramid.
- 44:16I don't think the Pyramid web
- 44:17framework really ever got
- 44:19types added to it.
- 44:20Somebody could go and create
- 44:21a typeshed stub or a types
- 44:24underscore pyramid you could
- 44:26pip install and then we'll
- 44:27add the types, right?
- 44:28I certainly see it being
- 44:29really valuable for third
- 44:30party things that are just
- 44:31not going to get the type
- 44:33attention they need.
- 44:33Yeah, I think typeshed is
- 44:34great.
- 44:35I've spent a lot of time on
- 44:36improving it.
- 44:37As Rebecca said, especially
- 44:39with a standard library,
- 44:39it's irreplaceable.
- 44:41For third party libraries,
- 44:42I think it's become less
- 44:44needed over time.
- 44:45It used to be that very few
- 44:47third party libraries had
- 44:49any types.
- 44:49Now that's obviously changed.
- 44:51A lot of libraries ship
- 44:53their own types, but still
- 44:54there are quite a few types
- 44:56of libraries left where
- 44:57there aren't inline types
- 44:59and typeshed can provide
- 45:00useful types.
- 45:01I think typeshed also
- 45:02provides a service because
- 45:03it has a really great
- 45:04framework for testing
- 45:05these types.
- 45:06We have tools like step
- 45:07tests and various type
- 45:09checkers that help to
- 45:11make sure these types are
- 45:12good and meet a high
- 45:14standard.
- 45:15So yeah, I think they're
- 45:16still useful for many
- 45:17libraries.
- 45:17Yeah, I was just looking at
- 45:18the types dash flask and
- 45:21I guess it must be, must
- 45:23be gone because now type
- 45:24flask must have it
- 45:25internally.
- 45:26So it's kind of an interim
- 45:27sort of thing.
- 45:28That's pretty cool.
- 45:29In general, typeshed has
- 45:29the policy that we remove
- 45:31the snaps from typeshed if
- 45:32they are in the library
- 45:34itself.
- 45:34I find these super
- 45:35valuable because if there's
- 45:37a library I want to work
- 45:38with and it just doesn't
- 45:39have types for whatever
- 45:40reason, you can install
- 45:41stuff from here and all
- 45:43of a sudden your editor's
- 45:43way happier.
- 45:44I mean, I know we, you
- 45:47all agreed on like the
- 45:48API boundaries and I did
- 45:49as well.
- 45:50It's like that's one of
- 45:51the really cool things.
- 45:51The other thing that
- 45:52really makes me excited
- 45:53about types is if I hit
- 45:54dot in my editor, I get
- 45:57a meaningful list of real
- 45:58information about what I'm
- 46:00working on.
- 46:00And so adding, adding
- 46:02these types of things are
- 46:03pretty interesting.
- 46:04I want to ask you all
- 46:05about sort of these rogue,
- 46:07rogue tools that do stuff
- 46:10with Python typing that
- 46:11maybe y'all didn't intend.
- 46:12Like we all mentioned
- 46:14Pydantic, we've got
- 46:15Typer and FastAPI, but
- 46:18even a little farther out
- 46:19there is a bear type.
- 46:21Are you familiar with
- 46:21bear type?
- 46:22Yeah.
- 46:22Bear type's interesting.
- 46:24You can import, they have
- 46:26fun.
- 46:27They have fun with their,
- 46:29their import names and
- 46:30stuff.
- 46:31But basically you can put
- 46:33a, either a decorator onto
- 46:35some sort of call site or
- 46:36something, or you can just
- 46:37do it to an entire package
- 46:40or entire modules rather.
- 46:41So just run bear type
- 46:43dot claw import bear type
- 46:45this.
- 46:45And then it actually turns
- 46:47into runtime type checks.
- 46:49Good idea, bad idea.
- 46:51Interesting.
- 46:52What do you all think?
- 46:53So un-Pythonic, you won't
- 46:54even open the webpage.
- 46:56People should feel free to
- 46:57write whatever code helps
- 46:58them make like better
- 47:00software.
- 47:01I haven't really used
- 47:01bear type much myself,
- 47:03but it's clearly useful for
- 47:04some people.
- 47:05And I think generally in
- 47:06designing a type system,
- 47:07we should try to
- 47:08accommodate all users who
- 47:09do useful things to the
- 47:10type system.
- 47:10And that includes things
- 47:12like Pydantic or bear
- 47:13type.
- 47:13It's pretty fast.
- 47:14It's not as big of a hit
- 47:15as you would, you would
- 47:17imagine.
- 47:18They, let me see, what
- 47:19are they, somewhere they
- 47:20had a really fun, fun
- 47:21saying in here, but here
- 47:23we go.
- 47:24Bear type brings Rust C++
- 47:25inspired zero cost
- 47:26abstractions into the
- 47:27lawless world of dynamically
- 47:29typed Python by enforcing
- 47:31type safety at the granular
- 47:32level of functions and
- 47:33methods against type hints
- 47:35standardized by the Python
- 47:36community.
- 47:37order one, non-amortized
- 47:39worst case time with
- 47:40negligible constant factors.
- 47:41Like, how about that?
- 47:43No, it's a pretty neat
- 47:43library and it's pretty
- 47:44fast.
- 47:45I honestly, I've never used
- 47:46it in production.
- 47:47Having type hints and
- 47:49squigglies in the editors
- 47:50or in the linters has always
- 47:53been enough for me, but I
- 47:54can see using this if it's
- 47:56really critical and you're
- 47:57having issues, maybe you
- 47:58want to catch some runtime
- 47:59errors.
- 48:00I don't know.
- 48:00It's not quite an endorsement,
- 48:02but it sure is like a, huh,
- 48:03that's different.
- 48:04I definitely think that the
- 48:06extent to which type
- 48:08checkers may have a
- 48:10different understanding of
- 48:11your code from what happens
- 48:12at runtime and there isn't
- 48:14anything built in to catch
- 48:15that is sometimes a pain
- 48:17point.
- 48:18And so the desire to have
- 48:19your type annotations, to
- 48:20find out at runtime if your
- 48:22type annotations are telling
- 48:23you a lie, it makes a lot of
- 48:24sense why people would like
- 48:26that.
- 48:27I mean, it's something
- 48:27used to from other languages
- 48:28where the type checker is built
- 48:30into the compiler.
- 48:30Right.
- 48:31You get like a runtime type
- 48:32cast, like cannot.
- 48:33We kind of get that if you
- 48:35try to parse a thing, you
- 48:37know, like put the int
- 48:38param around a string and
- 48:40it's not really a parsable
- 48:41as an int.
- 48:42But for like real type
- 48:43information, I think
- 48:44personally I would use this
- 48:45as like I might apply types,
- 48:48type checking to a module
- 48:50for debugging and development
- 48:52for a minute and just see
- 48:53what happens and then turn
- 48:54it back off.
- 48:55You know, I don't know that
- 48:55I'd just ship production code
- 48:57that way.
- 48:58But anyway, I got a couple
- 48:59more questions.
- 49:00We're getting shorter on
- 49:01time here.
- 49:02What was one of the
- 49:03harder questions that you
- 49:05all, harder decisions you
- 49:07all had to address on the
- 49:09council?
- 49:09I think the most
- 49:10contentious one was
- 49:11PEP 724, if I remember
- 49:14the number correctly.
- 49:15It was around a feature
- 49:17called type guards, which
- 49:19is around user-defined type
- 49:20narrowing functions.
- 49:22Initially, they find that in
- 49:23a way that later was found
- 49:24to be somewhat problematic
- 49:25and we basically came up
- 49:27with a better set of
- 49:28proposed semantics that
- 49:30maybe we should have done
- 49:30the first time around.
- 49:33And what this PEP proposed,
- 49:35and as you can see, I
- 49:36sponsored it, is that we
- 49:37basically changed the
- 49:38meaning of the existing
- 49:39type guards under certain
- 49:40conditions.
- 49:41What is a type guard?
- 49:42A type guard is a function,
- 49:43like there's a good example
- 49:44there, the isiterable.
- 49:46It's a function that tells
- 49:47you how to narrow something.
- 49:50So in this example, there's
- 49:52an isiterable type guard,
- 49:53which narrows an object to
- 49:55an iterable of anything.
- 49:56And then inside the func
- 49:58there, you can see if
- 49:59isiterable file, it knows
- 50:01that it's an iterable.
- 50:04And in this case, yeah, I
- 50:06guess it just narrows
- 50:07exactly to iterable any.
- 50:08That's one of the ways that
- 50:09type guards works.
- 50:10I see.
- 50:11And the type that returns
- 50:12kind of communicates to the
- 50:14type system, like that this
- 50:15function ensures that this,
- 50:18the thing that came in as an
- 50:19arbitrary object, in fact,
- 50:21is one of these.
- 50:22Okay.
- 50:22Interesting.
- 50:23Yeah.
- 50:23So that was a tricky one,
- 50:25huh?
- 50:25Any other standout, Rebecca or
- 50:27Carl?
- 50:27Well, the current discussion
- 50:28around what is the meaning
- 50:29of a float annotation, still
- 50:32unresolved, contentious topic.
- 50:34Okay.
- 50:34Gotcha.
- 50:35I mean, this on PEP724 is
- 50:38also what came to my mind
- 50:41immediately as well, because
- 50:42this was challenging
- 50:44discussion because, you
- 50:45know, like there were very
- 50:47conflicting considerations at
- 50:48play.
- 50:49It's like, what semantics
- 50:50did we want in the long
- 50:52term?
- 50:52And what did we want the
- 50:53type system to look like,
- 50:55you know, say like 10 years
- 50:56from now versus backwards
- 50:57compatibility and what the
- 50:59migration story would look
- 51:00like?
- 51:01It was quite tricky.
- 51:02I guess that's something you
- 51:03will always have to be
- 51:04cognizant of is like every
- 51:07change, even if it's an
- 51:08improvement, has to justify
- 51:10the fact that now you have
- 51:12challenges with the version
- 51:14history over time.
- 51:16I'm thinking like dict of string
- 51:19comma int with a capital or
- 51:21lowercase d.
- 51:22I've got people, I did a
- 51:24YouTube video showing
- 51:25something with the lowercase
- 51:26version because I was using
- 51:27something super modern like
- 51:29Python 3.11.
- 51:30And I got a message like,
- 51:32hey, Michael, you don't know
- 51:33how to write Python.
- 51:34Your code is broken.
- 51:35This code that you wrote just
- 51:37doesn't even run.
- 51:38I don't know how this is.
- 51:39I'm like, what version of
- 51:40Python is in?
- 51:403.8.
- 51:41Nope.
- 51:41You can't use 3.8 for that.
- 51:43You're going to need to get a
- 51:43newer one.
- 51:44You know what I mean?
- 51:44But like those are complexities
- 51:47that git added to Python
- 51:48because of that.
- 51:49Now you've got two ways to
- 51:51specify what a dict is.
- 51:52There's a preferred new way,
- 51:54but there's still the old way
- 51:55and it just, it sort of piles
- 51:57up.
- 51:58And it's very hard to ever
- 51:58actually get rid of the old
- 51:59way, even if there's no good
- 52:00reason to use it anymore.
- 52:01Exactly.
- 52:02Once it's there, it's written
- 52:04in ink pretty much, right?
- 52:05Like we have five or six
- 52:06different ways to format
- 52:07strings.
- 52:08Maybe with t-strings at six
- 52:09now.
- 52:10They're all going to still be
- 52:11there, right?
- 52:12So every change, every
- 52:13decision you make is not
- 52:14just a matter of, is it the
- 52:16right decision, right?
- 52:17It's the, is it worth it?
- 52:19I'm sure.
- 52:20Yeah.
- 52:21I don't know.
- 52:21How do you all balance that?
- 52:22Like that's tricky.
- 52:23With things like the dict
- 52:24chains, at least we sort of
- 52:25know we're moving towards
- 52:27better states and there's two
- 52:29things, but they mean exactly
- 52:30the same thing.
- 52:31So the confusion is not as
- 52:33bad.
- 52:34The problem with type cards
- 52:35is that we're going to change
- 52:36how some existing thing
- 52:38works, like what it meant.
- 52:39And I think there are good
- 52:41reasons that maybe that's the
- 52:42right thing to do, but the,
- 52:44it would also have been pretty
- 52:45confusing for people if their
- 52:46existing types suddenly started
- 52:47meaning something completely
- 52:48different.
- 52:49Absolutely.
- 52:50Hence float.
- 52:51Okay.
- 52:51What's coming next?
- 52:53Like 3.15, 3.16, do you all
- 52:55have things that are in the works
- 52:57that you think are going to come
- 52:58or debates that are brewing?
- 53:01For 3.15, the, there's a type
- 53:03dict feature coming, extra
- 53:04items.
- 53:05you can already use it in
- 53:07typing_extensions if you want
- 53:08to use it, but it will be in
- 53:10CPython as of 2.15.
- 53:12It's likely we'll have a small
- 53:13thing I added called disjoint
- 53:14basis, which is very technical,
- 53:17but helps type narrowing in some
- 53:18cases.
- 53:19Yeah.
- 53:19I think those are the things
- 53:20that are likely to make it.
- 53:22There's, we can only speculate
- 53:23about what else people can
- 53:24propose.
- 53:25We're sort of bound by what
- 53:26people actually write up as
- 53:27peps.
- 53:28We have to wait for Google to
- 53:28write the peps before we can
- 53:29approve them.
- 53:30I think there's PEP 747 for
- 53:32type form, which I think is
- 53:34not, I think we recommended
- 53:35its acceptance, but I don't
- 53:37think the steering council
- 53:38accepted it yet or it hasn't
- 53:39been accepted formally.
- 53:40I think that's on their
- 53:41plate.
- 53:41Yeah.
- 53:42Yeah.
- 53:42So that's also pretty likely
- 53:43to make it into 3.15.
- 53:45This is one example of a
- 53:46case that will be pretty
- 53:47useful to people working
- 53:49with type annotations at
- 53:50runtime because it'll allow
- 53:52you to, it's sort of a meta
- 53:53thing where you can annotate,
- 53:56have a type annotation that
- 53:57describes another type
- 53:58annotation.
- 53:59So that's useful if you're,
- 54:01if you're writing code that
- 54:02works with type annotations.
- 54:03Make the Pydantic of the
- 54:04world very happy.
- 54:05I am actually pretty excited
- 54:07about type form because,
- 54:10you know, I feel like there's
- 54:10a gap and we can express in
- 54:12the type system and we're
- 54:13good.
- 54:14And there are cases in the
- 54:15existing type system, like
- 54:17for instance, the cast
- 54:18function and some other
- 54:20cases where something takes
- 54:22any type expression as an
- 54:24argument.
- 54:24We actually don't have a good
- 54:25way to annotate that today
- 54:27and this will provide a nice
- 54:28way to express that.
- 54:28Let me pull up one thing
- 54:30really quick.
- 54:31Quick shout out to Will
- 54:31McGugan here.
- 54:32He just released his
- 54:33Toad project, which is the
- 54:35new, takes textual and rich
- 54:38and all that kind of stuff
- 54:39and applies it to like, what
- 54:40if we had a better Claude Code
- 54:42type of experience, which is
- 54:43pretty interesting.
- 54:44So the reason I'm bringing
- 54:45this up is, you know, final
- 54:47question.
- 54:47What about, do you all even
- 54:49worry about the role of like
- 54:52how types interact with AI
- 54:54and agentic coding tools?
- 54:56I know that if you have some
- 54:58code that has types on it
- 55:00and you give it to an AI, it's
- 55:02got a better chance of
- 55:03understanding what's happening
- 55:04than if you give it purely
- 55:05untyped code and say, tell me
- 55:07about this, right?
- 55:08It doesn't even know necessarily
- 55:09what's being passed to it.
- 55:10But is that anything you'll
- 55:12think about or what are your
- 55:13thoughts on this?
- 55:14Certainly think about it some.
- 55:15I mean, I think overall my
- 55:17feeling is that these coding
- 55:19agents seem to do better than
- 55:21more kind of the tighter
- 55:23feedback loops you can give them
- 55:25to work with.
- 55:26And so typing is another
- 55:27useful source of feedback
- 55:28where you can say, add type
- 55:29annotations and make sure the
- 55:30type checker passes and seems
- 55:32so it still seems pretty useful
- 55:34in that world.
- 55:35Yeah, you can easily write
- 55:36rules that say when you are
- 55:38done on anything I've asked
- 55:39you to do, always run ty or
- 55:42always run Pyrefly and make
- 55:43sure that there's no more, no
- 55:45new errors or at least or
- 55:46ideally zero errors, right?
- 55:48But nothing has been
- 55:49introduced.
- 55:50Yeah, pretty interesting.
- 55:51You other folks, Rebecca,
- 55:53Yela?
- 55:53Yeah, I guess in general, I
- 55:54think typing will remain
- 55:55useful for AI.
- 55:57We are probably rapidly
- 55:58moving to a world where a
- 55:59large proportion of all code
- 56:00is written by AI.
- 56:02Not everybody likes that
- 56:03opinion, Jelle.
- 56:03Not everybody likes that.
- 56:04I guess I, maybe my current
- 56:06line of work makes me think
- 56:07that's more likely to happen.
- 56:08You don't have to like the
- 56:09fact it's going to be night
- 56:10soon, but it's going to be
- 56:11night.
- 56:12You know what I mean?
- 56:12Like there's the, I just
- 56:14think there's so much
- 56:14momentum on this, at least in
- 56:16the next five years or
- 56:17something, that it's going to
- 56:18be really, it's, it's a
- 56:19truth of how many people are
- 56:21writing code regardless of
- 56:22whether individuals want to
- 56:23write code that way.
- 56:24You know what I mean?
- 56:25So I think it's a
- 56:25consideration.
- 56:26Yeah.
- 56:26Yeah.
- 56:26I forgot that you worked
- 56:27at OpenAI.
- 56:28So of course, I should pull
- 56:30up a codex example or
- 56:32something, shouldn't I?
- 56:32Yeah.
- 56:33Codex is great.
- 56:33Use it.
- 56:34No, but I mean, do you
- 56:35have any further insight into
- 56:36like the role of types
- 56:38and coding agents?
- 56:40I know that's not exactly
- 56:40what you work on, right?
- 56:41You're more at the lower.
- 56:42As Carl said, types can
- 56:43also be helpful for AI to
- 56:45understand code better and to
- 56:47get a better feedback loop.
- 56:48I feel like the very big AI,
- 56:49the board is like humans.
- 56:51And if AI makes, sorry, if
- 56:53typing makes humans better
- 56:54at writing understanding
- 56:55this code, they're probably
- 56:56also big AI better at it.
- 56:58It's the locality of
- 56:59information.
- 57:00You can read the function
- 57:01and know everything you need
- 57:03to know about what's going
- 57:03into it without bouncing
- 57:05around and trying to
- 57:06understand blocks of code
- 57:07and like what might've been
- 57:08created that's getting
- 57:09impacted.
- 57:09It's good for humans and
- 57:10also good for AI.
- 57:12Right.
- 57:12Rebecca.
- 57:12Because I don't have much
- 57:14need to, and I'll say I am
- 57:15maybe a little more skeptical
- 57:18than most of my coworkers
- 57:20about the quality of AI
- 57:22generated code.
- 57:23But that means I think I am
- 57:25particularly gung-ho about,
- 57:27you know, like get AI to use
- 57:29types, type checkers, keep
- 57:32the guardrails there.
- 57:33I think that'll be very
- 57:34important.
- 57:34Yeah, if it's going to make
- 57:35a mistake, don't let it at
- 57:36least like make the type
- 57:38system become disconnected
- 57:39and not working.
- 57:40Like it has to keep the types
- 57:42hanging together as a
- 57:43minimum bar, right?
- 57:44And you can easily set that
- 57:45up as an automation.
- 57:46Yeah.
- 57:47Interesting to think of it as
- 57:48guardrails rather than an
- 57:49accelerant.
- 57:50But yeah, 100% it is.
- 57:52All right, folks.
- 57:52I think that's it for all
- 57:54the time that we have.
- 57:55Thank you.
- 57:56Thank you for being here.
- 57:57Final thoughts before we go.
- 57:59Carl, I'll let you go first.
- 58:00Final thoughts for people
- 58:01out there interested in
- 58:02Python typing.
- 58:02Yeah.
- 58:02Well, first of all, thanks
- 58:03for having us on the podcast.
- 58:05Really appreciate it.
- 58:06And thoughts for people
- 58:07out there.
- 58:08I guess if you have ideas
- 58:10of how Python typing could
- 58:12be improved, discuss.python.
- 58:14Python.org is a good
- 58:15place to bring up ideas
- 58:16and discuss them with the
- 58:18typing community and see
- 58:19what positive changes we
- 58:21can make.
- 58:22Rebecca.
- 58:22First, thank you, Michael.
- 58:24This is a lot of fun.
- 58:26Last thoughts?
- 58:28Hey, so, you know, like
- 58:30we'll look at the typing
- 58:31council and sometimes think,
- 58:32oh, you know, like the
- 58:33PEP has like governance
- 58:34in its name, but I
- 58:35wouldn't say we're really
- 58:37a governing body or
- 58:39anything.
- 58:39It's like people who are
- 58:42using the type system,
- 58:43like users, they're the
- 58:44ones who come up with,
- 58:45you know, like all the
- 58:46best ideas, propose them,
- 58:47discuss them.
- 58:48And we're just here to
- 58:50sort of be like, hey,
- 58:53you know, like we have
- 58:53some background and like
- 58:55how type checkers work and
- 58:56maybe some of the history
- 58:57and we can provide input.
- 58:58But I just encourage
- 59:00people, if there's a
- 59:00change you want to see in
- 59:02the type system, you know,
- 59:03like propose it yourself.
- 59:05It's very friendly and
- 59:06open community.
- 59:07Yeah.
- 59:08Now people who have
- 59:09listened know a little bit
- 59:10more about how to do so.
- 59:11Awesome.
- 59:12Thanks.
- 59:12Jelle, final word.
- 59:13Yeah.
- 59:13Also, again, thank you for
- 59:14having me here.
- 59:16It's been great talking to
- 59:17all of you.
- 59:17I guess what I want to say
- 59:18is similar to what
- 59:18Carl and Rebecca just said.
- 59:20If you want to have
- 59:21something changed to the
- 59:22type system, I'd really
- 59:23encourage you to sign up
- 59:24for discuss.python.org,
- 59:25make a proposal, go
- 59:26through the process.
- 59:27It can be somewhat
- 59:28daunting, perhaps,
- 59:29especially if you have to
- 59:30create a PEP, but it is
- 59:32doable.
- 59:32There are several recent
- 59:34typing PEPs have just
- 59:34been community members
- 59:36who saw something they
- 59:37wanted to improve,
- 59:38proposed a PEP, and saw
- 59:40it to completion.
- 59:41If there's something you
- 59:41want to see in the type
- 59:42system, then you can do
- 59:44it too.
- 59:44Thank you all for keeping
- 59:46Python typing going
- 59:47strong.
- 59:48Really appreciate your
- 59:48time on the show.
- 59:49See you all later.
- 59:50Bye.
- 59:51Bye.
- 59:51This has been another episode
- 59:54of Talk Python To Me.
- 59:55Thank you to our sponsors.
- 59:56Be sure to check out what
- 59:57they're offering.
- 59:57It really helps support the
- 59:59show.
- 59:59Take some stress out of
- 1:00:01your life.
- 1:00:01Get notified immediately
- 1:00:02about errors and performance
- 1:00:04issues in your web or mobile
- 1:00:06applications with Sentry.
- 1:00:07Just visit talkpython.fm
- 1:00:09slash Sentry and get
- 1:00:11started for free.
- 1:00:12Be sure to use our code
- 1:00:13talkpython26.
- 1:00:15That's talkpython, the
- 1:00:17numbers two, six, all one
- 1:00:19word.
- 1:00:19And it's brought to you by
- 1:00:20our Agentic AI programming
- 1:00:22for Python course.
- 1:00:24Learn to work with AI that
- 1:00:25actually understands your
- 1:00:26code base and build real
- 1:00:28features.
- 1:00:29Visit talkpython.fm
- 1:00:30slash agentic dash AI.
- 1:00:33If you or your team needs
- 1:00:35to learn Python, we have
- 1:00:36over 270 hours of beginner
- 1:00:38and advanced courses on
- 1:00:39topics ranging from
- 1:00:40complete beginners to
- 1:00:42async code, Flask, Django,
- 1:00:44HTMX, and even LLMs.
- 1:00:46Best of all, there's no
- 1:00:47subscription in sight.
- 1:00:48Browse the catalog at
- 1:00:49talkpython.fm.
- 1:00:51And if you're not already
- 1:00:52subscribed to the show on
- 1:00:53your favorite podcast
- 1:00:54player, what are you
- 1:00:55waiting for?
- 1:00:56Just search for Python in
- 1:00:57your podcast player.
- 1:00:58We should be right at the
- 1:00:59top.
- 1:00:59If you enjoy that geeky
- 1:01:01rap song, you can
- 1:01:01download the full track.
- 1:01:03The link is actually in
- 1:01:03your podcast blur show
- 1:01:04notes.
- 1:01:05This is your host, Michael
- 1:01:06Kennedy.
- 1:01:07Thank you so much for
- 1:01:08listening.
- 1:01:08I really appreciate it.
- 1:01:09I'll see you next time.
- 1:01:18Voyager.
- 1:01:19Voyager.
- 1:01:21And we ready to roll
- 1:01:24Upgrading the code
- 1:01:27No fear of getting whole
- 1:01:29We tapped into that modern vibe
- 1:01:33Overcame each storm
- 1:01:34Talk Python To Me
- 1:01:36IceSync is the norm