Pydantic hacks Mypy detection: why type checkers crawl and how to fake your way to speed

charliermarsh · x · 2026-11-21

Charlie Marsh (author of Ruff/uv) shares a fun engineering find: Pydantic's source contains a Mypy-specific workaround — a massive CoreSchema TypeAlias is only constructed when a MYPY constant is true, because union types otherwise grind type checkers to a halt, hurting not just Pydantic but any code using it. His punchline: if you want your type checker to be faster on Pydantic, just tell it you are Mypy. Screenshot shows the relevant code in pydantic-core's coreschema.py.

Original post →

More from coding & agent

coding & agent channel →