https://xcancel.com/charliermarsh/status/1884651482009477368

We’re building a new static type checker for Python, from scratch, in Rust.

From a technical perspective, it’s probably our most ambitious project yet. We’re about 800 PRs deep!

Like Ruff and uv, there will be a significant focus on performance.

The entire system is designed to be highly incremental so that it can eventually power a language server (e.g., only re-analyze affected files on code change).

Performance is just one of many goals, though.

For example: we’re investing heavily in strong theoretical foundations and a consistent model of Python’s typing semantics.

(We’re lucky to have @carljm and @AlexWaygood on the team for many reasons, this is one of them.)

Another goal: minimizing false positives, especially on untyped code, to make it easier for projects to adopt a type checker and expand coverage gradually over time, without being swamped in bogus type errors from the start.

We haven’t publicized it to-date, but all of this work has been happening in the open, in the Ruff repository.

All driven by a uniquely great team: @carljm, @AlexWaygood, @sharkdp86, @MichaReiser, @DhruvManilawala, @ibraheemdev, @dcreager.

I’m learning so much from them.

Warning: this project is not ready for real-world user testing, and certainly not for production use (yet). The core architecture is there, but we’re still lacking support for some critical features.

Right now, I’d only recommend trying it out if you’re looking to contribute.

For now, we’re working towards an initial alpha release. When it’s ready, I’ll make sure you know :)

  • UFO@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    7 hours ago

    I don’t think a powerful type system can be added to python effectively. Even more convinced of this after reading “minimize false positives”.

    Otoh, how strong of a type system is required for effective development? Probably what can be shoehorned into python tbh.

    • FizzyOrange@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      42 minutes ago

      How powerful do you want it? Python’s type system is actually pretty good already and relatively sound when checked with Pyright (not Mypy though).

      It’s not Typescript-level, but it’s better than e.g. Java or C++.

      The main problem is Python developers writing code that can’t be statically type checked. E.g. using magically generate method names via __dict__ or whatever (I think lxml does that).

    • vrighter@discuss.tchncs.de
      link
      fedilink
      arrow-up
      1
      ·
      7 hours ago

      i don’t believe it’s possible either. For example the tree walker of the ast module takes the node passed to it, checks its type, gets its name, then looks for the method with that dynamically looked up name in your implementation of the tree walker and if it does (the user might not have implemented a visit method for that type of node), calls it and passes the node to it. All of this at runtime.

  • alsimoneau@lemmy.ca
    link
    fedilink
    arrow-up
    1
    arrow-down
    3
    ·
    7 hours ago

    I never understood the need for a Python type checker. If I wanted static typing I would code in Fortran.

    • Bogasse@lemmy.ml
      link
      fedilink
      arrow-up
      9
      arrow-down
      1
      ·
      12 hours ago

      Well, Astral as an history of managing to build tools that are actually very very clearly more usable than the pile of poop that Python ecosystem is 😅

  • onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    12
    arrow-down
    3
    ·
    edit-2
    20 hours ago

    I had a quick look and am already afraid that they are redoing what RustPython (parses python) is doing in order to build their type checker.

    After looking at it longer, yep, they forked RustPython. I’m not going to go through the history to find out why, but my first impression is that it’s a shame. Now two projects will be doing very similar work, IINM. However, it’s about time mypy had competition. It works fine for many cases, but sometimes just is a very frustrating experience.

    Anti Commercial-AI license

    • solrize@lemmy.world
      link
      fedilink
      arrow-up
      4
      arrow-down
      2
      ·
      20 hours ago

      I don’t like the current landscape of python type checkers.

      I figure that Python itself is at the bottom of this. It simply wasn’t designed for static types. Mypy is still of some use but if you want a statically typed language, trying to graft a type system onto a unityped language hasn’t worked out well as far as I know. See also: the Erlang dialyzer, Typed Racket, and whatever that Clojure extension is called. Even Scala has its problems because the JVM has its own type system that isn’t that great a fit for Scala.

      Also, why Rust as the implementation language? Just for speed? It seems a shame to not use Python/PyPy.

      • esa@discuss.tchncs.de
        link
        fedilink
        arrow-up
        4
        ·
        10 hours ago

        Astral is already a Rust shop; uv and ruff are written in Rust, and it makes sense for them to expand on what’s already considered very successful.

        Rust can enable a lot of speed and “fearless concurrency”; it also has a pretty good type system and a focus on correctness. They’d rather be correct than fast (C made the other choice, but is also from another age), but also show that that extra correctness comes with little runtime speed cost (compilation is another story).

      • Kogasa@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        13 hours ago

        Yes, speed and the benefits of all the tooling and static analysis they’re bringing to Python. Python is great for many things but “analyzing Python” isn’t necessarily one of them.

      • Ephera@lemmy.ml
        link
        fedilink
        English
        arrow-up
        2
        ·
        13 hours ago

        I mean, we’ll probably disagree on this, but in my not so humble opinion, Python is very unsuited for this large of a project, whereas Rust excels at large projects. I imagine, these folks might have a similar opinion, given that they’re building this tool in the first place. 🙃

        But execution speed is also not something I’d ignore in a tool like that. I remember having to work with Pipenv and Poetry, and it was just cruel, having to wait more than a minute for it to tell you whether it can resolve dependencies for a fairly small project. And you’ll want to run a type checker a lot more often that that.