Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is pyright actually helping? #503

Open
CompRhys opened this issue Jan 28, 2025 · 9 comments
Open

Is pyright actually helping? #503

CompRhys opened this issue Jan 28, 2025 · 9 comments

Comments

@CompRhys
Copy link
Contributor

I said that I would go through a fix some of the linting issues a few weeks back but there are so many pointless pyright complaints that result in # type: ignore needing to be added everywhere that it makes me question whether there's a benefit to using pyright if the API is so complex that adhering to the type pyright rules becomes an additional burden even for correct code.

@jduerholt
Copy link
Contributor

@bertiqwerty , what do you think?

@bertiqwerty
Copy link
Contributor

hmm... not sure. Can we deactivate the rules where Pyright is really wrong? I think we do not do a very accurate job regarding the types in BoFire. Maybe, there is some potential to improve. Can you give some examples, @CompRhys?

@CompRhys
Copy link
Contributor Author

My main issue with pyright is that there's no good way I can see to get it to run in pre-commit due to needing to install the package in the pre-commit env which I can't find a good solution for. As such it's something that will continually break because people "know" that their code works and so for development velocity often it makes sense to merge and fix later.

There are also weird redefinition choices that I needed to add in #505

@bertiqwerty
Copy link
Contributor

bertiqwerty commented Jan 30, 2025

Just for my understanding, do you think Pyright as a tool is not worth it or would you want to ditch static type checking altogether?

@CompRhys
Copy link
Contributor Author

Unless there's not a good way to get the tool to work locally in the same way as in CI my thoughts are it's an annoyance rather than a benefit, cf just using a ruff rule to say you have to include type hints (without a checker). In the linked PR i fixed all the pyright issues I get locally pinning the pyright version to 1.1.305 rather than using the newer versions but it still seemingly divergences due to py3.10 in CI and me using py3.12 locally. There are too many ways to use this particular tool in a manner than even fixing all issues locally it will break the linting CI.

@jduerholt
Copy link
Contributor

@bertiqwerty: what do you think about using such a ruff rule to enforce that the user actually uses types?

@bertiqwerty
Copy link
Contributor

In general, I am in favor of correct type hints. So I am still not sure what to do. Just a few temporary thoughts:

  • Just saying that there have to be type hints will probably lead to a lot of wrong type hints, Is this better than no type hints?
  • We could lint in the pipeline only e.g., the latest supported Python version. Then, the problem of different results with different Python versions should be less of an issue.
  • There are other tools like Mypy. Maybe they are easier work with. BayBE for instance uses Mypy.
  • Locally, I wouldn't necessarily want to integrate the type checker as a pre-commit-hook. Rather have it as plugin in my IDE to check the types already while typing.

I have to think about this. In the meantime, let's get some more opinions. @LukasHebing, @WaStCo, @R-M-Lee, @sleweke-bayer, what do you think?

@LukasHebing
Copy link
Contributor

I am also a fan of correct typing (@bertiqwerty). But with pyright, I had several problems:

  • I couldn`t reproduce the behavior locally
  • A lot of fails were actually wrong (code worked as it should, with the given types)
  • For some reformulations (same line of code), it took me hours to find the "pyright-correct" version. Very annoying.

However, in some places, it was helpful, e.g. to think about optional, None inputs that I forgot to test.

@bertiqwerty
Copy link
Contributor

bertiqwerty commented Feb 4, 2025

For some reformulations (same line of code), it took me hours to find the "pyright-correct" version. Very annoying.

Can you show some examples?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants