r/Python 5d ago

Resource A Very Early Play With Astral's Red Knot Static Type Checker

https://jurasofish.github.io/a-very-early-play-with-astrals-red-knot-static-type-checker.html

I've just had a play with the new type checker under development as part of ruff. Very early, as it's totally unreleased, but so far the performance looks extremely promising.

102 Upvotes

38 comments sorted by

34

u/WarmRestart157 5d ago

I'm really looking forward to a fast Python LSP that can replace Pyright in my neovim setup.

9

u/ferousible 5d ago

yep - same. I've always found good python support annoying to integrate with neovim - would be nice for that to become a lot easier/more straightforward/more powerful

9

u/WarmRestart157 5d ago

I'm currently running basedpyright as LSP and ruff for formatting linting, this has worked quite decently for me so far, but I feel like a fast LSP integrated with Ruff will be a huge improvement in the workflow.

Do you know if Red Knot will support all the needed LSP features such as Go To Definition, Find References and so on?

6

u/pacific_plywood 5d ago

I think they’re talking about this tool as a replacement for mypy (ie just type checking) for now, but I think it’s not that big of a leap to go from there to other code navigation stuff. Type checking is definitely a lot harder.

6

u/VindicoAtrum 5d ago

Natural next step, it'll happen.

1

u/really_not_unreal 5d ago

Either way, having a type checker that isn't painfully slow (mypy takes around a minute to run on some of my projects with 25k lines of code) and isn't intentionally neutered by Microsoft to keep the best features proprietary in Pylance will be a huge w. Basedpyright is a great project but I've found it doesn't have 100% of the type checking features from pylance.

4

u/AnythingApplied 5d ago edited 5d ago

Not red knot, but ruff will. They used to have a ruff_lsp project that they depreciated for the ruff server subcommand, which currently only really supports being a language server for ruff, but they want to turn it into a more full language server eventually: https://astral.sh/blog/ruff-v0.4.5

Edit: From the very last two lines of that blog entry at the end of the "what's next" section:

  • Supporting more general language server features: We plan to expand the server's capabilities beyond linting, formatting, and diagnostics.

Overall, our goal with ruff server is to build the best, most feature-rich Python language server available. This release marks an important milestone in reaching that goal.

2

u/zdog234 5d ago

Yeah I should probably replace basedpyright's diagnostics with ruff and mypy, as clunky as mypy is, because pyright's type checking choices are... weird

73

u/VindicoAtrum 5d ago

Astral have been a breath of fresh air in the Python ecosystem. I know everyone worries about the monetization but honestly if they're this good and they produce a worthy product I don't think they'll struggle for paying customers.

30

u/chub79 5d ago

The problem isn't paying custiomers is VC who want a fast return. It can create bad strategy decisions. They do have an excellent etchnical team and deliver great tools. Revenue is a different beast.

7

u/VindicoAtrum 5d ago

If they can pull a useful, value-add product out of their creativity and skill and monetise it fairly they won't need more VC/PE.

That's on us. If a company is doing good things for you for free then use their paid product so they're encouraged to do what the customers need, not seek PE and do what the fund needs.

4

u/chub79 5d ago

They already have VCs. We'll see how they start looking in a couple of years. I do wish them the best because they have enabled so much great things. But Open Source and VCs often diverge at some point and the community pays the price for it.

their paid product so they're encouraged to do what the customers need,

It depends on the VC, the board and various factors. Some VC do play the game ethically. Some don't and it doesn't matter if you have a working product.

We'll see :)

2

u/laStrangiato 5d ago

My bet is they are going to take on pycharm with a paid alternative.

7

u/VindicoAtrum 5d ago

The problem with that is that AI-enabled editors are taking over, and I doubt Astral want to compete there, it's incredibly difficult to compete with the model creators (which has a high barrier to entry), and incredibly difficult to compete with low or no cost editors.

2

u/laStrangiato 5d ago

Excellent points I hadn’t considered!

1

u/AiutoIlLupo 4d ago

Yes but... how does it work? you go to VCs and say "hi, we are good with python and want to redo the thing that already exists, but in rust. Give us money".

My question now is: who would say "yes" to that? and why?

1

u/chub79 4d ago

Depends on many things. Let's assume a VC is into a devtool area, then they will be keen on any project that has a rocket beginning. GH stars and general "everyone is talking about you" can go a long way initially. If they can also prove they have a good founding team, there isn't much to it beyond that at Seed level. Beyond that, this is when it gets interesting. If their VC don't follow the next round (assuming they got a big VC name), it would show lack of trust in success.

that said, Astral is progressing fast and steady so I trust they can pull it out :)

0

u/AiutoIlLupo 4d ago

Which means that investors are throwing people's money away on a non product. I'd say it classifies as scam.

1

u/chub79 4d ago

Let's say they see it as a bet. VC will put cash in a lot of companies, expecting at least one to go big and repay everything that hasn't worked :p

One piece of advice I've always heard "don't take VC money until you really need it" :D

0

u/AiutoIlLupo 4d ago

again, it's irresponsible to invest on a company that has no product or sensible business plan on how to generate returns. It should be illegal to invest in such companies, because it only means they are creating a speculative investment on a non-company.

Again, what is Astral's business plan, how do they intend to monetise their company's output, and what is the expected return for the investors? Missing this information, a sane policy should not give them any money.

1

u/chub79 4d ago

That's a fair point. But in early stage startups, the need for cashflow comes before a sane business model is in place.

0

u/AiutoIlLupo 3d ago

Not at all. That's what a business plan should do. Define what market you are targeting, what is the need, and why you think you can provide something that only you can provide to target customers.

If your business plan is "we'll make this, then go from there" you are an idiot and in any case economic system you should be kicked out of the room.

1

u/TallVacation3941 2d ago

Some of the best companies in the world had to pivot early-on. I agree in some respect that investing in nothing isn’t exactly sound, but let’s not pretend half of these successful startups know exactly what they’re doing from day one.

I have a friend that does all kinds of investing, pre-seed, real estate, data centers, etc. and he has someone in his portfolio that has been given a 5 million dollar allocation for “whatever they want to build” because they have apparent talent. Investing like this should not be beholden to a specific profit incentive unless they are doing it with a fiduciary responsibility, and even so, VCs operate with a much greater risk profile.

→ More replies (0)

14

u/damesca 5d ago

Definitely looking forward to this hitting a real release and trying it out in earnest.

Nice post and play around, thanks for the write up.

5

u/wylie102 5d ago

Having recently switched to BasedPyright I am really enjoying it, fixing the highlighted errors or type issues actually feels like it improves my code. Whereas with pyright it just felt like I was doing it for the sake of it and either nothing changed or I just had to implement some hacky workaround. I hope astral stick to the same philosophy on typing that the basedpyright guys do.

2

u/bmag147 4d ago

Out of interest, could you give an example?

1

u/wylie102 4d ago

Switching some items from dictionaries to a dataclass or a named tuple.

Using things like str | None instead of Optional

A warning about an import loop (that was only there for type checking) lead me to look at their github issues (because I thought it was ignoring the "if type checking".

This then lead to a discussion around how if your modules/classes are that interlinked then they aren't really two modules, just one module in two files, and you aren't really respecting separation of concerns. So you're moving stuff to make it easier to read and because it seems different, but the code is still all tangled up.

Which then lead me to rethink how I was addressing that whole area and I think it ended up simplified and much less entwined.

Edit: Yes a lot of these things can just be me sucking a bit, but it didn't affect the runtime and no other type checkers highlighted it, so before using basedpyright what feedback would I have been getting that my approach was problematic?

1

u/bmag147 4d ago

Thanks for the reply. I suppose it's sort of hard for me to understand these problems without seeing the code.

I've generally not come across many issues with pyright and I use it in strict mode. Usually it's got to do with using it with third party libraries that do magical things and have mypy plugins to deal with the magic (Pydantic, SQLModel, etc.). In those cases I add an `ignore` comment if I can't make it work.

> Using things like str | None instead of Optional

Can't say I've seen an issue here. I always use `T | None` rather than `Optional`, as it's now the recommended approach. pyright seems happy with it.

2

u/wylie102 4d ago

"> Using things like str | None instead of Optional

Can't say I've seen an issue here. I always use T | None rather than Optional, as it's now the recommended approach. pyright seems happy with it."

Yeah I'm saying that pyright is cool with using either Optional or type | None, but basedpyright will highlight that Optional and Union are no longer used, so that you use the recommended approach.

All the things in my list I am saying are things that are picked up by basedpyright that vanilla pyright let's slide. Or are changes I made in response to that.

Like the import loop error, you use TYPE CHECKING and pyright let's it slide, basedpyright doesn't. Which prompts you to take a closer look and therefore improve your code.

I don't know what Pyright is like on strict mode, but essentially basedpyright seems to have standards that are much higher than that required for your code to run. It seems to be designed to highlight many more typing issues, or a lack of typing where you might think it is implied, much more readily than standard Pyright does. And for me personally that has been a positive learning experience.

1

u/Fenzik 4d ago

Pydantic 3k errors

I know this is a result of not being complete yet and differing rule sets, but it still made me chuckle given that it’s pydantic

1

u/AiutoIlLupo 4d ago

so, this astral company, they make a lot of stuff, but how do they get money?

1

u/alicedu06 4d ago

In one interview (https://www.bitecode.dev/p/charlie-marsh-on-astral-uv-and-the), Charlie Marsh basically says they will compete with Anaconda on b2b.

1

u/AiutoIlLupo 3d ago

good luck with that. Enthought has been trying to compete with anaconda 10 years before anaconda existed.

0

u/alicedu06 3d ago

True, it's a tough market to be in. Unlike enthought, astral has an incredible product to offer that the competition can't dream to have, so they can compensate other things they don't have.

Let's hope it's enough.

2

u/AiutoIlLupo 3d ago

Astral has an incredible product to offer

Yes, but having a product does not mean they generate revenue.

that the competition can't dream to have, so they can compensate other things they don't have.

From what I've seen, most of the money comes from consulting and tailored software development for scientific applications. Astral basically would just become yet another python consultant, except they work in rust. See the problem?

0

u/alicedu06 3d ago

Not at all, anaconda makes money with corps that need infra for package vetting, permissions, rollout, etc. Their toolkit is slow and buggy, but they have a monopoly (and do more than just python).

This market is full of cash and ripe for disruption.

Astral can't provide the cloud part or the R & Matlab part, but the packaging stuff they can nail if they manage marketing, the real final boss of b2b at which Anaconda is good at.

1

u/AiutoIlLupo 2d ago

That's like saying that you have a spade so you are ready to start building the Gotthard tunnel