astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.55k stars 1.06k forks source link

Static type checking à la mypy #3893

Open saada opened 1 year ago

saada commented 1 year ago

Would be amazing if Ruff had static type checking. Mypy is a well known solution in this area as well as pytype, pyre, and others.

As a follow up, we could have some way of auto-fixing type annotations.

Thank you for this incredible project 😍

charliermarsh commented 1 year ago

I will admit that I'm interested in this and it fits into the vision of what we're trying to do, but it would be irresponsible of me to promise or commit to anything yet :)

NeilGirdhar commented 1 year ago

I'm not sure if you are aware, but Pylyzer is a Python type checker that's written in Rust. It might be worth seeing if there's a way to have all the desired features with less effort.

zanieb commented 1 year ago

Oh that's interesting! It uses Erg and isn't quite feature complete, I'm not sure if we could use it but it's great to see another Rust Python tool.

NeilGirdhar commented 1 year ago

I don't know much about Rust, but would it be possible for them to expose an API that Ruff could call into? If so, the Ruff and Pylyzer teams could work out an API that Pylyzer exposes and Rust could call into? Even if you don't end up using Pylyzer, knowing the API that Ruff needs would be useful if Ruff were to implement its own type analysis. (Just thinking out loud.)

thibaut-st commented 7 months ago

Is there any dev started on that feature? It would be so awesome to have all the essential python code quality tools in one fast as hell dependency!

nolanking90 commented 6 months ago

I'm interested in moving forward on this. I would like to begin working on features that could be exposed to ruff-lsp to add more of the traditional LSP capabilities, and it sounds like getting some type checking/inference working is going to be necessary before something like 'textDocument/hover' can be handled (by ruff-lsp) in a useful way.

Some input from the maintainers about implementation would be helpful, if this is still something the core team is interested in.

zanieb commented 6 months ago

Thanks for expressing your interest! Unfortunately the scope of this feature is far too large for external contribution, it will require major architectural changes to Ruff and extensive collaboration with our team. We're moving in this direction though. We can mark any related issues that would be good for external contribution with a "help wanted" label, as I'm sure there will be lots of smaller tasks that arise.

We're also recently kicked off a rewrite of ruff-lsp in Rust, see https://github.com/astral-sh/ruff/pull/10158. Once it's established, I'm sure there will be issues in that project that are good for contribution.

johnthagen commented 4 months ago

For those interested, looks like initial work for this is here

KotlinIsland commented 2 months ago

à la mypy

please don't make it like mypy, closer to pyright would be much more tolerable. although considering how based the maintainers are here, i'm confident they would know what they are doing

kszlim commented 2 months ago

Curious if there's a tracking issue for the progression of this feature? Would be great to gain some visibility into this (with the caveat that I certainly don't have any expectations around the arrival date).