- Podcasts
- Happy Path Programming
- #114 ty: Fast Python Type Checking with Carl Meyer
#114 ty: Fast Python Type Checking with Carl Meyer
Happy Path Programming
- July 25, 2025
- 1 h 5 min
- Season 1, episode 114
About this episodeCarl Meyer works on the ty Python type checker, built in Rust by Astral the creators of Ruff and uv. We chat about type systems, the…
Carl Meyer works on the ty Python type checker, built in Rust by Astral the creators of Ruff and uv. We chat about type systems, the evolution of static typing in Python, and the focus on performance.
Resources:
Richard Feldman: Roc compiler moving from Rust to Zig
Discuss this episode: discord.gg/XVKD2uPKyF
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#114 ty: Fast Python Type Checking with Carl Meyer
Welcome to Happy Path Programming. I'm Bruce Eckle. I'm James Ward. Welcome to Happy Path Programming. It is July 25th, 2025 and the the only thing I want to talk about before you get started is the summer tech forum on conference. Yes, on conference and that is September 8th through 12th. So that's coming up.
And if you go to summertechforum.com, you'll see we're all set up to register and everything. I just met with the with a professor at the local university and they, they had some people and a couple of professors who came to the Winter Tech Forum and we're totally jazzed by it. And so we're gonna have possibly 10 students will get, I think they'll they'll get sponsored.
Cool it. Was really nice having the students. And professors, it really, it really, you know, added to the breadth of our discussions and apparently they got a huge benefit out of it. It looks like Bill Venners of Scalf fame will be coming and are long time friend Diane Marsh. Diane gonna find Well, that's. How I kind of organized the conference with the idea that she would be coming because she said, oh, here's here are the weeks that I could come.
And so this is one of the. Ones that the dates based on Diane. 'S gotta choose, you know, gotta choose some reason to set the dates and yeah, the idea is yeah, Diane will that that's what she said. Both Bill and Diane will be here and oh, that'll be interesting and. This is in Crested Butte, Co, it is where we live and man, it's been a beautiful summer.
Oh, it's yeah, the views and the the spaces and and if we get bigger, they've got we can scale. Yeah, we can scale up if if that happens. Awesome. So, yeah. And we had a developer retreat over the 4th of July. I don't think I mentioned that. And that was. It was fun. I got to hang out for a little bit. Yes, you did start building some AI agents. Yes, that's right.
Yeah. No, it was a it was a very good time. Yeah. All right. Cool. Well. Today we have with us Carl Mayer, I said. Meyer. Meyer, sorry and maybe you do your background on? Yeah. So yeah, Carl and I met at the Pycon Typing Summit and I gave a little presentation there and there was a number of others and then we had a lot of conversations. And so yeah, that's how we decided. And Carl is with Astral.
And you're the lead on Ty is that? Right, yeah, I work on the Ty or type checker. Yep, and and how big is the team for that? Well, if you include the full project which includes type checker and LSPIDE features, let me think somewhere in the vicinity of eight. OK, OK. And you called it Ty is is. That how we we go for Ty Yeah, OK, yeah, I mean. Oh, like UV?
UVETY is it? But yeah, yeah, OK, Well, it sounds like short for type, but Ty, OK, that works. So you're working on Ty and so I think I tried it on my because I'm writing this Thinking in Types book for Python. And I tried it right when it became available and I know that it came up with all it instantly.
It's very fast, instantly came up with lots of issues with my code base which had previously passed my π and pyrite, but it was so early so I don't. I don't know what the OR it's. Just more strict and your code needs to be fixed. Probably more likely, more likely it was bugs in Ty if you tried it. Yeah, well, it came out.
Really early. So what's the state of it now 'cause it's a couple months later? Yeah. So I mean it's, it's much better now than it was a couple months ago. We're still, we're working towards so, So what we released before Pycon we called a preview or an alpha, I don't know. The germinology doesn't matter too much, but it was very, very early. Just wanted to get something out to show what we're working on and let people play with it a little bit. We're working now towards what we're thinking of as a beta release, which still won't be quite where we'd like it to be to really say like this is ready to ready to be your primary production type checker, but should be much closer than the alpha was and another step along the way. So we're targeting that for sometime in the next couple months hopefully.
So that is something that you could use the way people use Mypi today. So you can run it on the command line and then also an LSP. So, so it will plug into your editor and give you things like go to definition and all the the things that we expect from from an LSP server. So we wanted to do all of that, kind of provide the Python.
Makes sense that your type checker and your LSP are should be based on the same system so that the red squigglies in your ID are the same as. As yeah, when you when you run it as a batch. So the the typing summit is kind of a little bit of a blur in my mind now. Was it Ty that one of your goals was to be gradually, I mean, to allow people to gradually move into it?
Yeah, that is one of our design goals was Ty. So some of the existing Python type checkers the the experience if you adopted on a new code base that isn't currently typed. Even if that code base is fully working, in some cases type checkers will make assumptions. An example is like if you have a class and on that class you define an an attribute and you just say like X equals none and it's not.
There's no type annotations or anything. This is an untyped code base. Some of the existing type checkers will look at that and say, well you assign None to X, so I'm going to just go ahead and assume that X is always supposed to be None. It's type is None type or None and you can't infer. That it's an option or Yeah, it doesn't. It doesn't Python.
What's the option type? Yeah, there's optional, or you can just use a union with None, but The thing is, it can't. If you just, if on the class, the only thing it sees is X equals None, it's not going to look through the rest of your code base and say, well, I see this assigned here, this assigned over there. That's not real.
It's not really feasible from a performance perspective or incrementality perspective to be able to say that the our understanding of this type is going to depend on analyzing your entire code base and seeing every use of it. We kind of have to understand the type just from looking at its definition. And so existing type checkers will say, well, you assign none, therefore it's none.
Therefore, if somewhere else you try to assign an integer to it, that's an error. And then if you want to fix that error, you have to add an explicit annotation that says int or none, and then that fixes it. And we want to shift that a little bit just to make it so. So the result of those, that kind of decision is that if you have an untyped code base, even one that's working and you run a type checker over it, you tend to get a whole bunch of type errors initially. And then you have to sort of figure out which ones are real errors and which ones are cases where the type checker is making an assumption about your intentions that maybe didn't match your actual intentions or your actual usage. And then you have to sort of add annotations to correct these mistaken assumptions of the type checker. And so one of our goals, as much as feasible, is to avoid making those kinds of assumptions when we don't have an explicit annotation from the developer telling us what their intentions are.
So if we see a class and we see X equals None, we will actually infer the type unknown unioned with None, which is effectively a type that says at minimum, we know that this can be None, and therefore we can still issue an error. If we see you doing something with X that is invalid for None, we can say, well, we at least know that this X might be None, so we can issue an error on that.
But if we see you assigning something to X that's outside of None, that's an integer or whatever, because we've unioned it with unknown, we can still allow that and say, well, as far as we know, this could be, you could intend for this to be a union of none with something else. And we don't know what that is. And so that means when you run your type checker on the unannotated code base, you should get fewer errors initially.
And then as you want to opt into more strictness, you can do that very kind of naturally and incrementally by adding annotations. So as soon as you add an annotation then we'll enforce that. Is unknown one of the? I mean, is that a a standard type in Python? I don't remember OK 'cause I encountered it in TypeScript recently, but.
Yeah, yeah, that's that's a very good point. So unknown is kind of a a non standardized extension, something that Pyrite already does and we do it too. And really it's just so Python has the type any which represents essentially an unknown type. It's the dynamic type. So this is gradually like the bottom. Type or whatever.
And TypeScript has that as well. So it's not really the bottom type. It's kind of a it's, it's something specific to gradual type systems as opposed to fully static type systems as as you'd see in most sort of statically typed languages. And so, so the bottom type in Python would be, we call it never or no return.
And essentially that's the type that has no inhabitants. There's no no values that that are that type includes no possible runtime values. And the top type would be object, which is every Python value is an instance of object. So object is the type that covers all of the every possible Python object. So that's the top type.
And then any is something a little different. It's like it's an unknown static type or a dynamic type, which then the type checker essentially sort of throws up its hands and says, well, you can kind of do anything you want with this and we're not going to complain about it because we don't know what you mean. It's like outside of.
The type hierarchy. So you've got the type hierarchy with never an object you know at the bottom and top, and then any is like outside that it's the escape. Right. Or you can a way to conceive of it is it's like it's a. It is, it is, it is something somewhere in the type hierarchy, but we don't know where it is.
Is I think the clearest way to conceive it. It's an unknown static type. OK, so then we treat it as yeah. There there is a type, but we don't know what it is so. You're there is some type, yeah. When, when, So when you're analyzing a function, you're not and and you see something like the case you imagined you're not going through and looking for where it maybe get us gets assigned to something else and going Oh, well, that must be an enter, you know something.
Like, yeah, OK, let me let me finish my thought earlier on unknown and then I'll get to that question. It's a good question. So Python has this type any and what we do and what Pyrite also does is we sort of give two different names to any. It's really the same type. It's just this dynamic type and unknown static type.
But we use any where you've explicitly annotated that way. So you can in Python, you can do from typing import any and then you can use any as a type annotation to basically basically that says like, let me do whatever I want here and don't complain about it. Just assume I know what I'm doing. And so you can explicitly annotate that way. And so we use any for that.
And we use unknown for the same type, but where it originates from a lack of annotation. So if you just haven't put an annotation at all, then we'll use unknown. And really semantically it's the same thing, but we find it useful for a developer to see where, oh, I have the type any here. That means that somewhere there's an actual annotation that says any.
And if I see unknown, that means I just I'm missing an annotation somewhere, and that's a useful distinction for developers so. I think that is helpful to have like an explicit like this thing is, any versus the compiler doesn't actually know, so that's an unknown. But I can't explicitly type something as unknown, Is that that right?
No, it's not a standardized type. I don't think my π has this as far as I'm aware. And and you can't, I mean, so technically in Ty you could we, we have this sort of Ty extensions module, which is a bunch of non standard types that Ty uses, but that are kind of specific to Ty. And I can talk about some other interesting types in there later.
But so technically you can do from Ty Extensions import unknown and annotate something as unknown that exists mostly just so we can use it in our test suite. It's kind of a strange concept because the whole point of unknown is that it's a missing annotation. So to be able to. So it's not something that we're actually intending for people to use.
It's more just an implementation detail that. You're gonna specify specify any but exactly? Yeah, I can see why for your test you'd need to be able to. Reference. We wanna be able to name the type, but anyway, sorry, go ahead. And I think in TypeScript, unknown means this hasn't been initialized yet, so it's a little different.
I, I I'm not a TypeScript expert. My memory of unknown in TypeScript is that it's more in a sense like object in Python in that it's it, it could be anything, but it's not forgiving in the way that any or what we call unknown in Python are where it's like we'll let you do anything with it. In JavaScript, if something is typed as unknown, or in TypeScript if it's typed as unknown, that means it could be anything, and so we're basically gonna error if you try to do anything.
We thought we'd get cargo calls our way through it, but we can't. Yeah. So I can I'd like to back up and and ask like how what's your background in type checking? How did you get to this place where you go? Oh sure. I'll do this project that's. Great question, so before I was at Astral I was at Meta working at Instagram for about 8 years and trying to think. When I first came to Meta, I hadn't really done much with type checking or type systems or typing in Python at all. I mean, that was still pretty early days. Type annotations were introduced in Python 3 and they hadn't seen super wide use.
It's changed a lot, yes. But I think when I first started an Instagram, I worked on some things. I worked on the the transition to Python 3. So we moved the Instagram code base. Instagram server is a big Python code base. We moved that from from Python 2 to Python 3. And then we're kind of looking at, OK, we've done that, like what all is unlocked by by being on Python 3.
And one of the things was this new typing stuff. And for a very large code base with a lot of developers working on it and a lot of kind of people moving on and off the project, we felt like types would be a a big benefit. And we had a lot of developers coming onto the Instagram server code base who had previously worked on other typed code bases since they'd come into the Python And say, you know, where are my types? My, my IDE can't tell me anything and I can't, I can't figure out what this function takes and what it's supposed to return because I have no type annotation. So there was a lot of kind of developer sentiment internally. There was like, I, I want some, some static types here. So I think, I think we discussed it with Mike Krieger. He was the the CTO at Instagram at that time and he was really on board and excited about it.
And so we started experimenting with My pie. Anyway, Long story short over I think 2017 to 2019, that became my primary project at Instagram was kind of introducing typing to the Instagram server code base. We started with my Pie and then later replaced that with Pyre, which was a type checker built internally at Meta.
And over the course of a couple years, we went from zero type annotations in Instagram server to fairly close to 100% coverage in the in the sense of there's still any's and of course things like that, but almost everywhere where almost all functions had annotations. So that kind of got me into the topic, got me interested in it and.
One question on that, and I don't know if you can reveal details, but I'd be curious to know if there was any research done after that transition or before and after that transition to give us some data on did this increase productivity or developer happiness or like were there measurable metrics that all this work like could be shown to have an impact on?
Yeah, Yeah. No, that's a great question. As I'm sure you know, like measuring productivity is a huge can of work, Yes. So I wouldn't, I don't think we had anything there that I would put much, much faith in in terms of measuring productivity. We did at one point kind of try to do some studies on like prevalence of certain kinds of exceptions showing up in production and then requiring like a rollback or a hot fix. And we did at one point I think see some, I don't know how rigorous or statistical work was. My memory is a little vague at this point, but we did at one point see what looked like a significant decrease in type errors and attribute errors specifically showing up in production after the type transition. So there was some evidence of some improvement there. I think the strongest evidence we had was developer sentiment, and that was very clear.
It was very clear in the developer surveys that we did that people were very happy to have the type information available. Yeah, but what? So I'm not sure. I mean, I keep hearing from people, like as I'm writing this book, people go, oh, yeah, I really need to convince my team to use types and they're resisting. And so, you know, this is what I'm, this is what I'm looking for.
And I like all the people that I have direct contact with are like, oh, of course you want types that makes things better. But apparently there's, do you have any sense of like the, the portion of programmers who are going, why are you type resistant? Well, or, or they'll say things like, well, the language doesn't require it, so why would I do it? Or, you know, all that kind of stuff. I mean, it seems like those are the people that it'd be nice to move a little bit, yeah.
Yeah, no, I don't have any sense of numbers on that really. There might be some numbers and there's a yearly Python developer survey that happens. And I feel like when I looked at the last one, there were some questions about type checking in there. And it seemed like if I remember right, most people were using it in some capacity, but I don't remember the details on those numbers.
And those are the. People who voluntarily took the survey so. Yeah, exactly. It's self selected as well. Yeah, I think these days almost the strongest argument for type annotations in Python. I mean, I, I think there's a good argument to be made about, you know, catching bugs, but one of the strongest arguments is the LSP features, because a lot of the more powerful LSP features you just can't implement effectively without type information. And those LSP features are pretty useful, I think. And so just having your, your IDE be able to even just give you useful hover information about what the things you're dealing with and useful auto complete is really assisted by type information.
So I think that's a pretty, pretty strong argument in favor. And I, I think that as we do more LLM based coding that as the LSPS and type checkers can provide better information to our AI coding agents. I think that's where we're gonna see a ton of value from the type systems. Cuz of course I want my AI code assistant to generate code that actually works. And gosh, types are sure helpful in getting there. So I think that yeah, as I'm writing code in the IDE, that experience can be much better with types, but then AI generated is going to be a whole another place where we experience a lot of value from that. Well, and I find when writing code, I guess there was a little bit of a hurdle at the far beginning, but I have found that even if I'm doing something small, it helps me think about what I'm doing.
I think one of the most common objections I see is just people feeling like Python's a very dynamic language and they want to be able to kind of use the dynamic features. And then you try to type annotate some of those things and the type annotations, sometimes it's just not even possible with what we have or are able to express in the static type system. And in other cases it's possible, but the type annotations can get large and complex if you try to accurately express some of those things.
And I think the, the, the nice thing there is that it is a gradual type system, so it's never required. And if you want to use type annotations in the, you know, 80% of your code base where the annotations are fairly simple and work well, you can do that. And you can just leave the other 20% unannotated or use any, I mean, you always have that, that escape hatch. So you can use it where it makes sense and kind of bail out where it doesn't.
Yeah, if you're doing something like super weird and dynamic, then you can. Feels like some of some of the rust stuff is actually like given the anti type people some ammunition because you look at some of the rust types and you're like, Oh my God, that's that's a pretty significant block of type information. Yep, yeah.
I mean it goes back before Russ too. You can look at the C STL. So I mean sure theory types for a long time. Yeah, it's true. That's yeah. So my impression and of course I have some background. Well, Bill and James and I all have background in Scala and it seems to me like what a lot of the things that I see in the Python type system look like they just been lifted directly from Scala.
I don't know if that's just an illusion or not, but it seems that that's my impression. Do you have any, Were you on the like, typing committee or whatever for, you know, like the the size? Yeah, the Python. I'm, I'm on the typing council currently. So there's five of us who are kind of in charge of evaluating changes to the type system and proposed Peps and offering recommendation from the perspective it's mostly, largely type checker authors represented on that, on that council.
So I, I've been on there for about a year. I was not involved in the original design of the Python type system back in like 2014, so yeah, I don't know if there was some. Scala Scala influence in in the early days or or yeah. Yeah, I don't actually know. I mean, I'm, I'm sure there was some Scala influence.
Man, is that different. Yeah. Well, it's a different language that they're modeling, and they've made some different design choices in the type system. Yeah. And I think they're going more for easier transition. Like Elm was like so far over. It's like, OK, this is going to be a perfect functional system. No type failures ever.
At all whereas. TypeScript is like, OK, we assume you know, we know that your JavaScript programmers and you're used to just everything being all over the place. And so we, we can't restrict you too much and expect. You to come over but and interop with JavaScript. Is and yeah, the interop well and but, but it seems like Python's typing system is so much more.
Like TypeScript really, whenever it seems like whenever a conflict comes up between sort of usability and soundness, TypeScript has a real clear philosophy that they always choose usability. And there's, you know, good arguments in both directions. Oh yeah, but it feels more like C++ to me in terms of, oh, we always got to be backwards compatible with C and that opens up all kinds of hassles.
That compatibility ball and chain. Yes, absolutely. Ball and chain, Yeah. So it's like, I respect the pragmatism of it, but boy, I sure feel much more comfortable with Python's type system. I feel like we're gonna be able to go a lot further. Yeah. So you've been working on Ty and so you're writing mostly Rust code.
I'm probably not writing a lot of Python code would be my guest, but that's curious. And then one thing I was curious about with that is, is we we had Richard Feldman on a long time ago who he was, he was doing Elm and then he created his new language called Rock. And he'd originally written the compiler in for Rock in Rust and then had decided to switch it over to Zig. And we need to have him back on to to have that discussion. But but curious like like he found some challenges with building a type checker and compiler. Maybe it's more on the compiler side but in Rust and and it seen some benefits to Zig.
But what's your experience? Been building a type checker in Rust? Yeah, there's definitely some challenges. I would love to have a chance to sit down with Richard and and talk through in detail sort of what what are the the key challenges worth adhering into that convinced to blog post. On that which I'll post.
It and I think I've heard him talk about it on podcasts and I think his biggest issue was just compile time. Okay. The rest compile. Every time I've looked at Zig, I haven't wanted to learn it. But the compiler's fast. The compiler's fast and OK I. Guess so. It's OK. I don't know, I'd rather get a bigger machine or something than because I feel like you're giving stuff.
Like the company's kind of been built around building Python tooling in Rust with Ruff and with UV. And so just just, I mean, always team expertise is a relevant factor when choosing a tech stack. And so we're just from that perspective for Astral, it made sense to go. With Rust and the wicked speed of the runtime. And yes, of course, it allows us to build something that's very fast and we can have control over memory allocation and efficiency.
And so that's that's obviously very important to us. Yep. Right. And then what about concurrency? Do you does the? Do you use concurrency in the type checker and? Yes, that's not a huge benefit from from Rust is the sort of makes things concurrency safe by default unless you go go out of your way to make them unsafe. And so we've definitely made use of that. So Ty by default will just spin up a bunch of threads. Use all the cores.
Use all the cores and distribute the work across them, and that makes a huge difference in the performance. Nice, yeah. And so, yeah, other other challenges or interesting bits about writing the type checker in Rust with anything else on that experience that's. Yeah. I mean, I guess one interesting note there is that we made the choice to use Salsa, which is a library. It was developed I think initially for I think it initially grew out of work on Rust C, the Rust compiler, although I don't think it was ever actually used in Rust C, There's some shared ideas and then it's it currently powers Rust analyzer, which is one of the popular LS PS for for Rust. And so Salsa is a kind of a general purpose incremental computation engine.
So essentially what it allows you to do. I guess maybe I should take a step back and talk about the problem, which is that if you don't want to just build A1 shot kind of command line type checking tool, but you want to build a responsive LSP server for an IDE, then it's pretty important that you can. If you have a very large code base and somebody makes, you know, one letter change in one file somewhere, you don't want to spend however many seconds it takes you, you know, with some of the existing type checkers, it would be minutes. With Ty, it's seconds.
But you still don't want to send multiple, you know, seconds or 10s of seconds re analyzing the entire big code base from scratch. You want to be able to take the type information for the whole code base that you already had and make sort of the minimal updates that you need to make based on this one little change to get to a correct new understanding as quickly as you can.
And that's a very difficult to do accurately if you just kind of try to do it ad hoc and sort of track all of these dependencies of what needs to be invalidated when something else changes. And I know for some of the existing Python type checkers, that's been a, a big area of investment and recurring bugs over time is, you know, not getting the right answer after incremental change or missing updating something after incremental change and having your incremental results not matching the results you'd get from scratch. So that was something that was important to us to try to avoid. And So what Salsa does is it provides a general purpose framework or a library where you write your, your logic as Salsa queries.
And Salsa will actually under the hood kind of automatically track as you execute a Salsa query. It'll track what other Salsa queries called in the process of executing it. And Salsa behind the scenes will kind of build up this entire dependency graph. And it does that automatically based on what your code is actually doing. So you don't have to, you don't have to make sure and remember, oh, I got to invalidate this or I got to mark this dependency. It just all happens automatically. And then if you tell Salsa, OK, you know, you tell Salsa, these are your inputs, these are the files. And if you tell Salsa this input changed, then it can just kind of run that through the dependency graph and just automatically figure out everything that has to be invalidated.
And so you can essentially it means that we can write our logic without even thinking about incrementality or dependencies. We just write it kind of straightforwardly. And Salsa just handles that whole problem for us just kind of magically, which it's kind of amazing. Yeah. I mean, that sounds huge. That seems like one of the biggest challenges in writing a compiler or type checker is managing that graph and the invalidation, You know, the different points in that graph. So the fact that Salsa gave you the foundation to build that seems like a huge benefit for her for what you're doing. So I don't know if this is an elephant in the room but I want to ask about.
UV is very fast compared to other Python package management tools. Rough was a very fast linter. Yeah, so. What's the linter? The linter is called Rough, and that was actually the first thing that was built. That was probably good. Yeah. That was built before Astral existed, yeah. And everybody goes, oh, rough, you got to use rough. And it was like, yeah.
Yeah, this is rough. Is also built in REST. It's also built in rest Yeah, it was kind of a it was kind of a hobby project for Charlie, our founder, and then it turned out to be very popular. And so that's kind of that's where asked for all the company came from was like, oh, apparently there's a lot of interest in in fast Python tooling. So yeah, performance was definitely the the top complaint that we were hearing from the community and from companies about the existing Python type checking options. And so that was the motivation to do a new Python type checker was to build something faster.
The Pyrfly is also very fast, roughly in a similar ballpark to TUI. Pyrfly came along after we had started working on TUI. Meta was obviously also feeling the need for faster Python type checking internally. Because they were using Pyr. They were using Pyr, right? Which one of them was? Previous, I mean, was Pyrfly just well, I don't know if you know this and we're going to interview them so I can ask them then, but was that do you know if that was just a translation across to Rust from whatever they. My understanding is that Pyrfly was not just a translation of Pyr to Rust, but it was more of a well from scratch project I think.
Yeah, it. Makes sense? Yeah. I think they wanted to sort of move on from some of the architectural limitations of Pyre and do it better the second time we're in, OK. OK. So Ty was kind of the ecosystem of type checkers and Python. There wasn't at the time of starting Ty a great high performance for both batch and incremental compile speeds. And so it was like, great, we've got these other Python tools built in Rust and people love them. Let's start building our own type checker. That's gonna be super.
Yeah. But I also understood that it's, I mean, maybe I heard you being interviewed on a different podcast, but I thought there was a goal to integrate all these tools together. From Astro like uvm rough and Ty all together or something. Yeah, for sure. I mean, I would say a big part of the inspiration for kind of Astral in general is Cargo, which you're familiar with your work in Rust. And Cargo does provide a really nice kind of integrated experience for everything that you need compilation and type checking and.
It's all kind of in one package management, all of that is kind of in it's lovely, a nice streamlined unified experience. And that's where we would like to get to with Python. And we're certainly not there yet, but we're sort of trying to build all the pieces. And we definitely have visions for how, how Ty and UV can integrate well so that, you know, you don't have to configure Ty because we can just look at your UV configuration. And then we know all about your project. There's, there's a lot of potential. And you know, things like just knowing what your dependencies are in principle allows us to provide really good say like import auto complete.
It's like if we know you're, you're trying to use this name and it's not imported, well, we know what all your dependencies are, so we can. So there's a lot of potential potential ways that that integration can work. I would say at the moment, that's more of like a vision and our our priority right now is building a really good type checker and LSP integration is more of a future thing.
And in the long term, we'd also like to integrate Ty and rough. If you look at the rough issue tracker, you'll see like good chunk of the issues that have been hanging around for a long time are tagged with this type inference, I think, or type type something label. And that basically means, yes, this is like something we would like the Lynter to do, but we can't because we just don't know enough about your code base type information. Yeah, right.
Exactly. And so long term, we would like the Lynter and the type checker to be just sort of one continuum where it's like, well, you've got your core type checking rules and you've got your more opinionated lint rules, but they're all built on the same kind of core type inference information. So, but again, that's.
It is weird how you could imagine, okay I've got my lender, my code formatter, my type checker, all these things. You could imagine them not needing knowledge of each other, but in reality they all actually need to know about all of all the things. Like formatting is an interesting one too, where it's like, yeah, you to be able to format your code well, you actually need to know about the types and know what, what can break where and all these sorts of things. So yeah, it's it's an interesting thing where where I think the naive approach is to build these as separate tools, but in reality they work much better when they actually have shared knowledge.
Is that a thing? I, I mean, I guess I'm, I'm imagining like your code analysis and you were talking about Salsa keeping track of everything. Is that a thing where we end up like analyzing your code and saving that state somewhere to increase speed the next time? Or maybe it comes along with the with the package that you bring in. That's a great question.
Salsa doesn't actually currently have support for persistent caching. So I mean, Salsa does of course a bunch of caching in memory. So as you have your LSB server running it, you know, has all the things it's already calculated, then it can invalidate just the ones that need to be invalidated and then rerun those.
But it doesn't currently involve include any ability to write any of that state out to disk and then load it up later on a totally separate run. And that's something that we would like to add. We've had some discussions about how important is that really like if it's fast enough, maybe you don't need that, maybe it can save some memory.
Yeah, for sure. I mean, we, we've already obviously been testing Ty on some, some big code bases that we have access to. And so we have a rough idea of what the performance looks like. And, and certainly on very big code bases, even Ty, you know, you can on a very big code base, you might be talking about 2030 seconds to analyze the whole thing. We've seen something like that.
And so even at that level, incrementality is very important. Obviously how how important it is, it's still unclear to us how important it is to write it to disk because you can imagine paying 20 to 30 seconds kind of like at the beginning of the day when you sort of first start up your editor. That's reasonable.
Obviously you don't want to pay it every time you make a change to the code, so. Yeah. Is there like daemon mode for TYI think some compilers now can like spin up a daemon so you can essentially get, you know, the the stateful piece without not through the LSP. Like when you're in your IDE having the LSP is is the useful waste way to have that daemon for incremental support.
But but outside of that, like a yeah. We do. We do have with with the TYCLI. Also, we have a dash dash watch option where it'll just gotcha, sit, sit there and look for changes and incrementally respond. Yeah. So the watch is that that Damon mode And then coming back to the rough Ty piece, I'm curious your thoughts on what is the role of a linter if you have a good type checker, like what are the things that should be lint rolls versus types?
Yeah. No, that's a great question. We think a lot about and I mean we've, I think because we have this vision that ultimately we want to have type aware linting built on top of Ty in some ways that allows us to narrow our scope of what we think belongs in the core type checker compared to say my π which has some more opinionated rules or options where it's like, well, this is not something where your code is going to fail. But yeah, maybe it's stylistically better to do it this way or clear.
And we try to say for most of those things, kind of draw the line and say, yeah, we think that's that belongs in a lint rule that could be powered by Ty. But and ultimately, I think in the user experience that we envisioned, there may not be a huge difference in these. They're just different kinds of rules that emit different diagnostics. But there may be differences in, you know, what we enable by default, for example.
But I think it's, it's sort of a continuum of like if you use a name that you never defined, well, clearly your program is going to crash with a name error. And that's something we probably want to report. And if you, if you try to like add an integer and a string together, like we know that's going to fail at runtime, that's definitely a type error that we want to report in the type checker. And then on the other end of the continuum you have, I mean, if you look at Ralph's rule set, it has some extremely opinionated rules that not everyone is going to agree with. And those definitely fall under the linter side of things. Yeah, is.
So in some ways the linter is the ability to add stricter, stricter controls that people can opt into. Yep. But I guess I'm, I'm curious like could those be expressed in types if you had a sufficient, A sufficiently capable type system, ignoring the, the piece of opting into them, you know, incrementally or something.
But but generally, could even those those stronger rules be in the type system rather than, or in the type checker rather than in a linter? I mean, I think I'd probably have to look at some specific cases. I mean, there's a lot of different potential that rules and the answer might be different for different ones.
I mean, in principle you can pack, you can express a lot in something that you still call a type system. I mean you look at some some of the more advanced type systems, things like effect systems and there's all kinds of things that you can in principle express in a type system. A lot of that stuff would require kind of more complexity in the community that we want this in the type system, right?
It's not maybe something that Ty is just gonna kinda go out and do. Yeah, on our own, necessarily. So it's almost like the linter is type checker plus plus that you can opt into specific features of. I guess that makes sense to like have that ability for people to have that opt in to essentially additional rules.
Yeah, I think in general, I was, I was the way I would describe a linter rule is that it's sort of is a rule that says, you know, this pattern or way of writing some piece of code is bad. And we think this is a better way to do it. And so the linter is going to tell you that and hopefully ideally maybe even automatically fix your code to the new pattern. And that's a little different from a type checker rule, which is telling you, like, your code is going to fail. Like, that's maybe a rough way of drawing the distinction, yeah.
You mentioned you just now you mentioned effect systems and that's what we've been working on for the last, I don't know, it's five years now I guess or whatever. And one of the so we're working on translating effect oriented programming into TypeScript effect library. And so it's it's a little bit of a Wild West experience.
And I've been looking at Python, you know, Python's type system so much closer to Scalas seems like, do you know of effect systems in Python? Because I think we've looked around, just seems like it would be so much easier of a fit. Because I don't, I don't know. I don't know of anyone who is kind of tried to do that. Doesn't mean it's not out there.
I'm just not familiar with it. I mean, certainly. Someone tried or started or something but. Port of Zeo to Python I. Think it was, yeah. But then they they gave up. And maybe it was just because it was too early. But now it seems like you could almost. I guess we keep thinking we're gonna get to a point where we could just set the AI onto the, you know, say, translate Zeo into Python.
I think the the better one would be KEO, which is a algebraic effects system. I think that one may port more directly to Python. That's the the Kotlin 1. No, no, it's, it's still Scala. Yeah, yeah. It's certainly a topic that comes up regularly, even if people don't always realize what it is they're asking for.
I mean, I would say every month or so there's a new thread on the Python discussion forum about somebody wanting to know what effects exceptions aren't modeled in the Python type system. Or there was recently a thread about people wanting to model pure functions. And like all of these things, ultimately they're talking about effect systems. Yeah, yeah, it'll happen.
And it'll probably happen with algebraic effects, right? Not with a monadic effects. OK, but cool. And then I had a question, Oh, we're what's what's kind of on the horizon for Ty and and Python types type system stuff? Yeah. I mean, I think something that's both in Ty and I think hopefully on the horizon for the Python type system, which I think would be interesting to talk about is intersection types. So the the Python type system is. It's what's called a set theoretic type system, which basically means that a type represents a set of possible runtime values.
It's like you have this set of possible random objects in this other set and you union together, and then that's a new type. So you can sort of imagine expressing a wide variety of possible types that way. But Python has only ever had the union connective. And if we know about sort of sets, there's more that we can do with two sets than union, then we can other.
Exactly. There's. The intersection of the sets or there's the negation of the set. And that's not been something that's been, well, it's interesting. It's not explicitly been part of the Python type system. But if you consider Python type checkers do do type narrowing or what's called flow typing, and there's different names for it where you can sort of say, well, at the beginning of this function, X is int or None.
But then I say, if X is not None. And so then the type checker knows that inside that block now it's just int, right? We've excluded the possibility of none. And if you, if you really look at that, or if you look at more complex cases like if is instance X, whatever, essentially what you're doing is an intersection, right? Like you have a type and then you check for another type. And essentially the new type in that narrow block is going to be the intersection of what you knew before and what you just established.
And so really all the current Python type checkers do have, at least in in principle, some form of intersection type in order to enable that. But it hasn't ever been, it's been typically kind of ad hoc and not sort of an explicit first class concept. Yeah. And so that's one of the things that we set out from the start to do in Ty because we think that it is something that the Python type system needs and will probably have sooner or later is we built our type narrowing from the beginning on a fully generalized kind of set algebra with unions and intersections and negations all built in.
So when I was talking earlier about that Ty extensions where we have all of our sort of non standard extensions, you can actually. So in addition to just doing our sort of implicit flow typing or type narrowing using intersection types under the hood, we also do allow you to from Ty extensions, import intersection and then you can write your own arbitrary intersection and negation types and and play around with those. So that is also something I think is coming for Python typing.
There's some people working on a PEP to officially add intersection types to the Python type system, so. That's part of the typing committee or. Yeah. So one of the people I know is working on that is somebody who's on the typing council. So eventually whatever whoever whoever ends up actually writing a PEP, it will come to the typing council for discussion and editing and presenting it on.
So I was curious what you touched on, which is kind of the process of evolution of all of this, because you've got the the Peps and, and kind of Python, actual Python type system stuff. And then you've got the type checkers that are built on top of that. But then you have a way to add extensions to the language essentially through in, in Ty.
Is that like get that kind of summary right? You got that totally right. I mean, there's all kinds of interesting things to touch on there. It's there's, there's sort of the category of there's the Python type system and the typing council is mostly in charge of that. So if if there's a PEP that really is just expressing some new type semantics, but otherwise it doesn't change the language like it doesn't need to like nothing in the runtime, Python runtime would have to change to accommodate it in In those cases, the Python Steering Council, which is the group in charge of approving Peps for the Python language, basically just delegates to the typing council and says that's, that's your domain.
But there are cases where we want to do something in the type system that and typically the place where it intersects is in not always, but often it's in syntax. Sometimes it's in like runtime behaviour of like how type annotation introspection works, but there are various areas where type system changes will intersect with the runtime and we actually need to change the Python compiler to support some new syntax. So change the runtime behaviour of small. Things being a deferred or whatever it is. This would be an example of that. There is syntax and type information. Right, exactly.
That was a change that encompass both. We wanted to introduce better syntax for expressing callable types or arrow types in, in the Python type system. And so that was one where we had to, we wrote up a PEP and we went to the steering council and said, here's what we'd like to do. And, and actually in that case, the steering council said no, they were like, this is too much, too much new complexity in the syntax just to support this particular use case for typing. And we don't want to do it.
So there is occasionally some tension there, like the the Steering Council is trying to look out for the the language as a whole and you have to balance those things. It's an interesting setup that's very different, I think than most other languages. Where most other languages, it's like you've got 1 central team that is developing the language, the syntax, the compiler, the type system, like all that stuff under kind of 11 house. And in, in the Python case, you've got you've got different type checkers, you've got the like the core specification with its contributions and then the pets like it's, it's an interesting way, way for things to evolve. And so it seems like it's working like things are evolving and yeah, but it is a very different set up I think than. Other languages in small teams rather than a monolith. Yeah, Which?
Yeah, the micro service approach to language design. And you look at packaging too. I mean, it was a big, it was a big deal when pip actually got adopted in the standard library. But and even now it's sort of halfway adopted, right? Like you have to run Python dash M insure pip to actually download pip. But but before that, you know, it was the same way for packaging.
Like there was no packaging tooling provided by Python at all and it was all just third party projects. Yeah, yeah. Thanks. And then yeah, back to future, any any interesting kind of language type things that you're beyond, You mentioned intersections, beyond intersections, anything that that is exciting on the type horizon?
I mean there's, there's various Peps in flight that I think will be good additions to the type system. There is an interesting one that I think. I think we, the typing council recently recommended acceptance of it. I don't think the steering council is officially acted on it yet, but it it kind of OK.
Taking a step back, one of the things that's interesting about Python is that unlike TypeScript, types aren't totally erased at runtime. So type annotations are still available for introspection at runtime. And this is actually kind of, I think to the surprise of some of the folks who originally developed the Python typing system, I don't think we're really expecting this.
They were really envisioning it As for static type checkers. But there's really been an explosion of projects using Python type annotations for runtime purposes. Like Pidantic is a really well known example of that. And like Fast API does some of this. So there's a lot of projects that are very popular that make runtime use of type annotations. And so that involves then writing code that kind of operates on type annotations and the runtime objects that are created that sort of represent a given type annotation. Like when you when you express some type concept in annotation like callable bracket, bracket int, you know, whatever, that actually turns into some kind of runtime object that allows you to kind of introspect the information you gave in the annotation.
And so there's all these kind of objects and, and, but there was never, there wasn't a good way to code, right? There wasn't a good way to actually type code that did this reflection on type annotations. It's all very meta. So there's a PEP called type form that adds like a generalized way to sort of express that this runtime object is a runtime representation of some type expression.
So that's an interesting one, probably for a more niche audience, but. Yeah, boy, yeah. The, the, the way the ability to actually have nominative typing in this dynamic language I've come to really appreciate because I've been studying how people do it in TypeScript. And there's a, you know, there's a way to watermark it, but it only lives at compile time. And then if you want to be it at runtime, you have to put in a type tag.
And then sometimes people will still attached to the prototype information and I'm I'm I'm still very confused by all this and, and to be able to just have it there, you want to know the type, you can find it out. You don't have to jump through all these hoops is just seems very important to me after seeing it in TypeScript. So in this world, is there?
Is there already like a standard AST library that all the type systems use? Or? Or if you do want to query a runtime the type information, how does that how's that actually represented in types? Yeah. So I mean, I guess there's a distinction here between you. What you can query at runtime is type annotations. So you can like if a class has some attributes that are annotated or if a function has its arguments and return type annotated.
Then at runtime, if you have a, if you have that class or if you have the function object, you can query and say, OK, how is it annotated? What were the parameter in return type annotations? And that's a little different from like querying at runtime, you know, what is a static type checkers understanding of the type of this variable at this point in control flow or something.
That's something that doesn't really exist today. So it's really around the annotations for this particular annotation, not around the AST of the types of runtime. Right. Gotcha. That's right. Yeah, I mean. For the annotations, it's great. I've used fast API and fast MCP and the way that you can annotate things and it all just magically works is pretty awesome.
Yep, Yep. Nice. Well that's cool. Great. Well, anything else? My brain is full. Yeah. Yeah. Well, thank you, Carl and that. Was an hour. Yeah, yeah, I know my fast with right on. Yeah, thanks. And I hope we intersect in the future. Good. Yeah, Thanks very much to both of you. It's a pleasure to be on. Appreciate you having.
