4 ms·
I've not tried Pyright, but mypy on any realistic, real-world codebase I've thrown at it emits ~80k errors. It's hard to get started with that. mypy's output i
by deathanatos 1y ago
I've not tried Pyright, but mypy on any realistic, real-world codebase I've thrown at it emits ~80k errors. It's hard to get started with that.
mypy's output is, AFAICT, also non-deterministic, and doesn't support a programmatic format that I know of. This makes it next to impossible to write a wrapper script to diff the errors to, for example, show only errors introduced by the change one is making.
Relying on my devs to manually trawl through 80k lines of errors for ones they might be adding in is a lost cause.
Our codebase also uses SQLAlchemy extensively, which does not play well with typecheckers. (There is an extension to aid in this, but it regrettably SIGSEGVs.)
Also this took me forever to understand:
from typing import Dict
JsonValue = str | Dict[str, "JsonValue"]
def foo() -> JsonValue:
x: Dict[str, str] = {"a": "b"}
return x
x: JsonValue = foo()
That will get you:
example.py:7: error: Incompatible return value type (got "dict[str, str]", expected "str | dict[str, JsonValue]") [return-value]
- koakuma-chan 1y ago> There is an extension to aid in this, but it regrettably SIGSEGVs. Love this.
- veber-alex 1y agoI don't use mypy so I can't comment on it but at least from what I have seen pyright is deterministic in it's output and get output json. Regarding the ~80k errors. Yeah, nothing to do here besides slowly grinding away and adding type annotations and fixes until it's resolved. For the code example pyright gives some hint towards variance but yes it can be confusing. https://pyright-play.net/?pyrightVersion=1.1.403&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAiSAxjAFBkBSAzmCgGoCGANgK4CmUAvFNTCFAA%2BhEjADafEABooAIhp0mbdrIC6FACbtgUYGDAAKAJRQAtAD4oChiw4AuMlCfOAHnZGkJ-GZNXcoAN6yjLLusgBGsgC%2Bjs5OIOwwrCAoUC5kQA https://pyright-play.net/?pyrightVersion=1.1.403&code=GYJw9g...
- mixmastamyk 1y agoI recommend first starting with pyflakes and later ruff on a huge old Python project. Do file by file. When done, do typing similarly.
- zelphirkalt 1y agoI used mypy just fine for a previous job. If you are getting 80k errors, that means you are either starting very late to use the type checker and have done many dubious things before, or you didn't exclude your venv from being type checked by mypy.
- FreakLegion 1y agoEveryone stubs their toe on container invariance once, then figures it out and moves on. It's not unique to Python and developers should understand the nuances of variance.