consensus-specs icon indicating copy to clipboard operation
consensus-specs copied to clipboard

Replace mypy with ty

Open jtraglia opened this issue 6 months ago • 8 comments

https://github.com/astral-sh/ty

The new type checker by Astral. I bet it's a lot faster.

jtraglia avatar Jun 16 '25 06:06 jtraglia

Is MyPy speed a (real) problem?

ty is not stable:

Warning

ty is in preview and is not ready for production use.

We're working hard to make ty stable and feature-complete, but until then, expect to encounter bugs, missing features, and fatal errors.

Moreover, the CL pyspecs use type expressions like List[Validator, <integer expression>]. Type checkers are not supposed to handle them (i.e. a form of dependent type). So, there must be some configuration workaround. It somehow works with MyPy, but can potentially cause problems when switching to ty, if it doesn't have equivalent functionality.

The dependent type problem looks like a more important problem to me, since bugs, which in theory must be caught by static type checking, can slip (as a type checker should be configured to ignore dependent types, e.g. by replacing them with Any). In particular, MyPy might be more suited to resolving the issue, e.g. via writing a MyPy plugin (however, such a plugin alone is not enough).

ericsson49 avatar Jun 16 '25 09:06 ericsson49

Is MyPy speed a (real) problem?

No, this is not a real problem 😄 this issue is just a reminder that I would like to look into it (pros/cons).

I am a fan of Astral products. I am aware that it's not stable. The dependent type problem does seem important.

jtraglia avatar Jun 16 '25 09:06 jtraglia

The dependent type problem does seem important.

I've opened #4384 issue. Initially, I was thinking about code preprocessing + MyPy plugin. However, I think we can have a more generic solution to the dependent type problem, which allows switching to other type checkers like ty in future.

ericsson49 avatar Jun 16 '25 13:06 ericsson49

@marioevz is this what we are using in STEEL?

leolara avatar Jul 21 '25 09:07 leolara

@marioevz is this what we are using in STEEL?

Not yet, but we are going to explore switching at some point too!

marioevz avatar Jul 21 '25 12:07 marioevz

@marioevz is this what we are using in STEEL?

Not yet, but we are going to explore switching at some point too!

Then, let's pioneer here :-)

leolara avatar Jul 21 '25 13:07 leolara

As @ericsson49 mentioned, I don't believe it's currently possible because of our types.

jtraglia avatar Jul 21 '25 13:07 jtraglia

I am expressing estuthiasm that perhaps we could try to try it first if it becomes more stable :-)

I see that neither solves the problem of dependent types.

leolara avatar Jul 21 '25 15:07 leolara