Description
Bug Report
Mypy began publicly breaking PEP 747 support in @beartype four days ago. Unfortunately for both mypy and @beartype, @beartype leverages PEP 747 literally everywhere. Hundreds upon hundreds of lines of labyrinthine spaghetti code across the @beartype codebase have already been annotated with typing_extensions.TypeForm
. Breaking PEP 747 thus breaks the entirety of @beartype (with respect to mypy-driven static type-checking, anyway).
Mypy now emits 169 false positives against the @beartype codebase – all duplicates on the same tired theme of:
beartype/_data/hint/datahintpep.py:136: error: Variable "typing_extensions.TypeForm" is not valid as a type [valid-type]
beartype/_data/hint/datahintpep.py:136: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
Moreover, mypy_primer
tests against @beartype! Since GitHub Actions-based continuous integration workflows on this repository leverage mypy_primer
, PRs on this repo like #18690 are now littered with red badness suggestive of critical failure. Red means bad.
Interestingly, pyright
has shipped experimental support for PEP 747 via:
# In "pyproject.toml":
[tool.pyright]
enableExperimentalFeatures = true
When enabled in this way, pyright
accepts @beartype without complaint. Pretty sure pyright
has supported PEP 747 for... wait. Has it really been over a year now? Oh, Gods. No! My time just up and dilated again. 😅
I'm at a bit of a loss as to what to do. The false positives are pretty intense. I should probably pin the @beartype test suite to mypy < 1.16.0
for the time being. Instead, I've taken the easy way out. I've temporarily disabled mypy integration in our test suite. That doesn't particularly help mypy_primer
, but at least @beartype CI now passes. And isn't that what truly matters?
This issue fills me with deep regret. I've come to love and adore mypy. Mypy keeps @beartype honest. Sadly, @beartype no longer knows how to satisfy mypy's unbidden desires.
Advice Nobody Wanted or Asked For
This is the section where @leycec says stuff nobody wants to hear.
pyright
has the right approach here. I note that mypy does have a comparable --enable-incomplete-feature
command-line option. That option doesn't appear to support PEP 747 at the moment, though. That's a shame. @davidfstr's preliminary PR supporting PEP 747 at #18690 cleverly adds --enable-incomplete-feature=TypeForm
, which would then have allowed @beartype to continue satisfying mypy.
Tragically, mypy 1.16.0 shipped without that PR. #18690 may not have been perfect, but the perfect is the enemy of the good. That PR was probably good enough for --enable-incomplete-feature=TypeForm
. Nobody except @beartype was going to enable that option. Instead, the current approach of rejecting PEP 747 altogether is the enemy of the good. Something is better than nothing.
mypy 1.16.0 leaves @beartype with nothing. This is why bears cry. 😿 <-- pretend this is a bear
To Reproduce
mypy_primer
. Pretty sure that's always the answer.
Allow me to now publicly thank and congratulate @hauntsaninja both for mypy_primer
and for including @beartype in mypy_primer
. Python Gods above! What a wonderful regression tester that is. 🥰
Expected Behavior
Mypy used to just superficially ignore PEP 747. While (of course) non-ideal, that was still a lot better than blowing hot chunks everywhere. If --enable-incomplete-feature=TypeForm
support isn't quite ready yet, perhaps mypy could simply revert back to superficially ignoring PEP 747?
Sometimes, the old times really were the good times.
Actual Behavior
169 errors on the theme of:
beartype/_data/hint/datahintpep.py:136: error: Variable "typing_extensions.TypeForm" is not valid as a type [valid-type]
beartype/_data/hint/datahintpep.py:136: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
This depresses me. I'm getting teary-eyed just thinking about all this.
Your Environment
- Mypy version used: 1.16.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files):
[mypy]
files = beartype/
no_implicit_reexport = True
show_error_codes = True
[mypy-click.*]
ignore_missing_imports = True
[mypy-importlib.metadata.*]
ignore_missing_imports = True
[mypy-numpy.*]
ignore_missing_imports = True
[mypy-pkg_resources.*]
ignore_missing_imports = True
- Python version used: 3.9—3.13
People Interested
I now summon everyone who cares about PEP 747 and then some! My home boys @davidfstr, @JelleZijlstra, @JukkaL, and @erictraut are the main gotos. Please help solve @beartype's many problems.