News for hackers. Stuff that matters.
Re:Ty: A fast Python type checker and language server by tmvphil on Wednesday May 07, 2025 @01:47PM (#43918640)
Just compared the time to check on a fairly large project:

- mypy (warm cache) 18s

- ty: 0.5s (and found 3500 errors)

They've done it again.

Re:Ty: A fast Python type checker and language server by _carljm on Wednesday May 07, 2025 @02:52PM (#43919324)
(ty developer here)

This is an early preview of a pre-alpha tool, so I would expect a good chunk of those 3500 errors to be wrong at at this point :) Bug reports welcome!

Re:Ty: A fast Python type checker and language server by joshdavham on Wednesday May 07, 2025 @04:56PM (#43920482)
Any rough estimates of how much faster you expect ty to be compared to mypy? I'd be super curious to know!

I was also one of those people who, when first trying Ruff, assumed that it didn't work the first time I ran it because of how fast it executed!

Re:Ty: A fast Python type checker and language server by _carljm on Wednesday May 07, 2025 @05:29PM (#43920754)
We're looking forward to hearing what your experience is! There's a certain amount of roughly-constant overhead (e.g. reading all the files), so generally ty will look relatively faster the larger the project is. For very large projects we've seen up to 50-60x faster or more. We haven't really put a lot of work into targeted optimization yet, so we aim for it to get faster in the future.

It will certainly be slower than Ruff, just because multi-file type analysis more complex and less embarrassingly parallel than single-file linting.

Re:Ty: A fast Python type checker and language server by mil22 on Wednesday May 07, 2025 @01:59PM (#43918779)
Great, but how does it compare to Pyright on the utility / performance curve? Pyright is mature and already very fast.

https://github.com/microsoft/pyright

Re:Ty: A fast Python type checker and language server by nine_k on Wednesday May 07, 2025 @02:18PM (#43918990)
Pyright is good, but it's quite a memory hog. (Yes, I have plenty of RAM on my machine. No, it has other uses during development, too.)
Re:Ty: A fast Python type checker and language server by bjourne on Wednesday May 07, 2025 @04:55PM (#43920476)
Pyright is only for type-checking and it lacks many features you'd expected from a modern LSP (I forgot which). Hence, it was forked and someone created basedpyright to fix it: https://github.com/DetachHead/basedpyright
Re:Ty: A fast Python type checker and language server by dathinab on Wednesday May 07, 2025 @05:44PM (#43920867)
To extend on this:

In python it's pretty common to have LSP separate from type checking separate from linting (e.g. ruff+mypy+ide_specific_lsp).

Which to be fair sucks (as it limits what the LSP can do, can lead to confusing mismatches in error/no-error and on one recent project I had issues with the default LSP run by vscode starting to fall apart and failing to propose auto imports for some trivial things for part of the project....)

But it's the stack where pyright fits in.

Re:Ty: A fast Python type checker and language server by geekraver on Wednesday May 07, 2025 @06:17PM (#43921082)
The pylance team has started exploring this, namely whether it makes sense to have an API for type checkers that is not the LSP, as language servers have a somewhat different goal in which type checking/inference is an enabling technology. This could allow multiple different language servers to be built on top of different type checkers (and the type checkers can run out-of-proc, so implementation languages can be different). https://github.com/microsoft/pylance-release/discussions/718...
Re:Ty: A fast Python type checker and language server by insane_dreamer on Wednesday May 07, 2025 @05:43PM (#43920862)
in my experience pyright is unable to infer many inherited object types (compared to PyCharm's type inference)
Re:Ty: A fast Python type checker and language server by lemontheme on Thursday May 08, 2025 @02:37AM (#43923646)
PyCharm definitely excels on more ‘dynamic’ code but the number of times I’ve pulled in code written by colleagues using PyCharm only to get a rainbow of type errors from Pyright is too damn high.

The PyCharm checker seems to miss really, really obvious things, e.g. allowing a call site to expect a string while the function returns bytes or none.

Maybe my colleagues just have it configured wrong but there’s several of them and the config isn’t shared.

Re:Ty: A fast Python type checker and language server by 0xFF0123 on Wednesday May 07, 2025 @05:58PM (#43920967)
Pyright is incredibly slow in my experience, I've seen it take over a minute on complex codebases
Re:Ty: A fast Python type checker and language server by mil22 on Wednesday May 07, 2025 @08:00PM (#43921700)
I tested it side-by-side on my ~100Kloc codebase.

Ty: 2.5 seconds, 1599 diagnostics, almost all of which are false positives

Pyright: 13.6 seconds, 10 errors, all of which are actually real errors

There's plenty of potential here, but Ty's type inference is just not as sophisticated as Pyright's at this time. That's not surprising given it hasn't even been released yet.

Whether Ty will still perform so much faster once all of Pyright's type inference abilities have been matched or implemented - well, that remains to be seen.

Pyright runs on Node, so I would expect it to be a little slower than Ty, but perhaps not by very much, since modern JS engines are already quite fast and perform within a factor of ~2-3x of Rust. That said, I'm rooting for Ty here, since even a 2-3x performance boost would be useful.

Re:Ty: A fast Python type checker and language server by the_duke on Thursday May 08, 2025 @01:55AM (#43923456)
Compilation / type checking depends on a lot of trees of typed data, and operating on those tree nodes. That's something where a statically typed language with custom data structures that allows for optimised representations makes a big difference, and where a lot of the fancy optimisations in v8 don't work so well.

There is a reason Typescript moved to a typed language.

Re:Ty: A fast Python type checker and language server by mil22 on Thursday May 08, 2025 @06:44PM (#43932105)
Let's hope you're right and that translates to even higher performance for Ty compared to Pyright. There are of course many variables and gotchas with these sorts of things.
Re:Ty: A fast Python type checker and language server by rtpg on Wednesday May 07, 2025 @09:51PM (#43922364)
I don't get why so many people go to bat for pyright, my experience with it has been pretty miserable. Open enough instances of it and you're in OOM city. It works, but often gets confused... and of course the absolute audacity of MSFT to say "let's go over to pyright, and by the way we're going to carve up some stuff and put it into pylance instead", meaning that it's totally not within the actual spirit of open source.

I would like to just not use it, but the existence of pyright as a _barely_ functional alternative really sucks the air out of other attempts' continued existence. Real "extend/extinguish" behavior from MSFT.

Re:Ty: A fast Python type checker and language server by lemontheme on Thursday May 08, 2025 @02:30AM (#43923617)
If you haven’t checked it out already, basedpyright is pyright with all the arbitrarily carved out functionality put back in – plus some extra features that you may or may not find useful depending on how strict you like your typing.

Can’t recommend it enough

Re:Ty: A fast Python type checker and language server by rtpg on Friday May 09, 2025 @02:06AM (#43934200)
To be honest I can't respect a project that names itself like that. I am a working professional.
Re:Ty: A fast Python type checker and language server by mil22 on Thursday May 08, 2025 @06:42PM (#43932096)
I tried all the type checkers available as of ~1 year ago, and Pyright worked the best for me. It's not perfect, but it's better than any of the pure Python checkers. Memory is cheap (unless you're buying it from Apple I guess...). Would I take a faster type checker with better memory footprint? Heck yes, assuming equal or superior functionality.
Re:Ty: A fast Python type checker and language server by rtpg on Friday May 09, 2025 @07:42PM (#43941962)
Memory ain’t that cheap on laptops in general! The bigger issue is less “pyright” and more “every tool out there being as heavy as pyright” + docker etc… but things are getting better IMO
Re:Ty: A fast Python type checker and language server by js2 on Wednesday May 07, 2025 @02:11PM (#43918924)
I have no doubt that it will be faster than mypy, but:

> This project is still in development and is not ready for production use.

Re:Ty: A fast Python type checker and language server by rybosome on Wednesday May 07, 2025 @02:37PM (#43919184)
> They’ve done it again.

Indeed they have. Similar improvement in performance on my side.

It is so fast that I thought it must have failed and not actually checked my whole project.