tqec icon indicating copy to clipboard operation
tqec copied to clipboard

Add mypy check in pre-commit config

Open Zhaoyilunnn opened this issue 7 months ago • 3 comments

Is your feature request related to a problem? Please describe.

Not really a problem, but I think it might be good for developers.

Maybe we should add mypy to pre-commit, not it will not run automatically when committing. And cloud CI can report type error even when committing successfully at local machine.

I am not sure if this is a problem to others, because including more checks in pre-commit also increase the time cost before a commit and can frustrate people I guess.

Describe the solution you'd like

maybe add this to pre-commit config

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the feature request here.

Zhaoyilunnn avatar May 14 '25 17:05 Zhaoyilunnn

I am fine with it, but it can be slow as you noted. Have you tried it locally? If yes, what's the usual wait time when committing?

In a related effort, I am thinking about switching to Astral's toolchain since a few months, and the lack of a mypy-like replacement held me, but with the introduction of https://github.com/astral-sh/ty that might be the good time to try the migration. If ty is as fast as it claims to be, that might be fine for commit times.

nelimee avatar May 15 '25 07:05 nelimee

I am fine with it, but it can be slow as you noted. Have you tried it locally? If yes, what's the usual wait time when committing?I

I haven't try it locally before creating this issue. I usually run mypy src/ manually and it takes several seconds to finish.

After trying https://github.com/pre-commit/mirrors-mypy, I observe inconsistent output, i.e., the pre-commit runs with many errors (seems to be false-positive) but mypy src/ returns no error. I have checked that the versions of mypy are consistent (v1.15.0), maybe there're some weird issues when running mypy in pre-commit consider it runs in a isolated environment: https://github.com/pre-commit/pre-commit/issues/1580.

Anybody interested in this can have a try in my experiment branch

If ty is as fast as it claims to be, that might be fine for commit times.

That seems to be a promising solution, I'll try it later if nobody takes this issue

Zhaoyilunnn avatar May 15 '25 09:05 Zhaoyilunnn

I haven't try it locally before creating this issue. I usually run mypy src/ manually and it takes several seconds to finish.

Yes, this has been my experience with mypy too. It can take some time for mypy to run.

I observe inconsistent output, i.e., the pre-commit runs with many errors (seems to be false-positive) but mypy src/ returns no error

It is also possible that pre-commit might not be taking the mypy configuration settings in pyproject.toml into consideration. I have had this happen with ruff in another project.

purva-thakre avatar May 16 '25 00:05 purva-thakre

I think this issue can be closed or migrated in favor of @purva-thakre 's recent effort in migrating to Astral's toolchain?

Zhaoyilunnn avatar Jun 06 '25 09:06 Zhaoyilunnn

I think this issue can be closed or migrated in favor of @purva-thakre 's recent effort in migrating to Astral's toolchain?

We are missing a specific issue to try out ty from Astral's toolchain. Maybe this issue would be the right one to do that?

nelimee avatar Jun 06 '25 10:06 nelimee

We could also think about switching to uv if we want to completely migrate to Astral's toolchain. https://docs.astral.sh/uv/

purva-thakre avatar Jun 06 '25 16:06 purva-thakre

We could also think about switching to uv if we want to completely migrate to Astral's toolchain. https://docs.astral.sh/uv/

That would make sense in my opinion

nelimee avatar Jun 06 '25 16:06 nelimee

Do we want to try & implement ty now or wait until it is stable?

Image

purva-thakre avatar Sep 10 '25 13:09 purva-thakre

Do we want to try & implement ty now or wait until it is stable?

If ty does not miss any critical features, I prefer to use it now because everything from astral is truly amazing.

inmzhang avatar Sep 10 '25 13:09 inmzhang

Indeed, everything from astral is amazing.

@Zhaoyilunnn Do you want to try implementing this?

purva-thakre avatar Sep 11 '25 00:09 purva-thakre

Indeed, everything from astral is amazing.

@Zhaoyilunnn Do you want to try implementing this?

I won't be able to work on TQEC until next month.. so it would be nice if you or anybody can fix this issue earlier

Zhaoyilunnn avatar Sep 11 '25 02:09 Zhaoyilunnn