Open AlexWaygood opened 2 months ago
We recently added a TypedDict
-heavy feature in altair
.
Not sure if this helps as real-world examples, but sharing as red-knot
came up during review
mypy
performance here has a lot of room for improvement
Nice! I'll add altair to mypy_primer. You may also be interested in https://github.com/python/mypy/issues/17231#issuecomment-2379375287 , I think it makes mypy significantly faster on your workload.
Code that creates large unions (explicitly or implicitly) is known to be hard for type checkers to analyze in a performant way. Both mypy and pyright have had lots of issues regarding performance for these, and both have implemented several optimizations to deal with them. We should add at least one benchmark (probably several) that measures how we do on this.
Common themes that come up in this area are:
Literal
types (Literal[1, 2, 3]
desugars toLiteral[1] | Literal[1] | Literal[3]
from the type checker's perspective, so "medium-sizedLiteral
types" quickly end up creating huge unions)Enums. A similar issue to
Literal
types. If you have an enum like this:Then in some cases,
x: A
can desugar tox: Literal[A.X] | Literal[A.Y] | Literal[A.Z]
TypedDict
sReferences
Here are some references that are worth looking at (and from which we might be able to derive benchmarks). The great thing about all of these is that they are performance issues that we know real users encountered when their type checker was checking real code. I've tried to exclude anything specific to recursive type aliases, since that feels somewhat out of scope for this issue:
Mypy
Pyright