mypy 1.1.1 no longer respects # type: ignore[attr-defined]
when importing from typing
#14871
Labels
bug
mypy got something wrong
Springtime salutations, wonderful mypy devs! The Sun shines bright, the Canadian nights are still as cold as an icepick, and the bugs infest every corner of my codebase.
Bug Report
mypy ≤ 1.0.0 correctly respected
# type: ignore[attr-defined]
comments when importingtyping
attributes not available in the current version of Python.mypy ≥ 1.1.1 no longer does so, instead emitting an erroneous warning referring to an irrelevant error code (i.e.,
"misc"
) as well as one warning for each such attribute. Examples follow or my middle name isn't "Beardy Bald Guy".To Reproduce
The above code is copied verbatim from the @beartype codebase, which I maintain for the good of QA-kind. The above code used to pass muster under both mypy and pyright. Now, only pyright remains happy:
All is no longer well here. @beartype's userbase will now be assaulted with spurious warnings they can do absolutely nothing about. Even I can't do anything about these warnings! And I'm the @beartype guy.
Moreover, these warnings are arguably harmful with respect to runtime typing. The
typing_extensions
module may be an unconditional improvement over thetyping
module with respect to static typing – but that definitely doesn't extend to runtime typing. Why? Because the runtime API of type hints defined by thetyping_extensions
module substantially differs in non-standard and non-trivial ways from that defined by thetyping
module. It's effectively infeasible for runtime type-checkers to support both. Ergo, runtime type-checkers typically only support type hints defined by thetyping
module.@beartype breaks this trend a bit. We actively support a subset of type hints defined by the
typing_extensions
module (e.g.,typing_extensions.Literal[...]
), despite those type hints providing a non-standard runtime API – but that's only a subset and that's only because Microsoft themselves vociferously complained on our issue tracker about this. What Microsoft wants, one gives to Microsoft.Expected Behavior
Silence! Sweet, blessed silence!
Actual Behavior
Loudness! Horrid, accursed loudness! Please see above.
Your Environment
mypy.ini
(and other config files): None.Thanks so much for all the tremendous volunteerism over these many, long years. You are dedication incarnate. Much ❤️ from the snow-encrusted Canadian wilderness.
— @leycec, the @beartype guy
The text was updated successfully, but these errors were encountered: