mypy: allow_redefinition = true#203
Conversation
| [tool.pytest-enabler.mypy] | ||
| # Disabled due to jaraco/skeleton#143 |
There was a problem hiding this comment.
I have a PR open for most if not all. Issue is also now closed.
8309735 to
e935449
Compare
| # Is the project well-typed? | ||
| strict = False | ||
| # More lenient, but still safe, reassignments | ||
| allow_redefinition = true |
There was a problem hiding this comment.
I'm inclined to say let's leave this as the default. In general, it's an anti-pattern to redefine variables. In fact, should we in distutils just provide spot exemptions for this behavior?
There was a problem hiding this comment.
Up to you! It happened in only 1 place in distutils (reference PR)
But personally use this option because it's what pyright and ty also do. AFAICT mypy didn't use to do it because it's more complex and had false-positive edge cases. Between 1.20 and 2.0 mypy even had 2 different implementations for allowing redefinitions, which got stabilised in 2.0. See https://mypy-lang.blogspot.com/2026/05/mypy-20-relased.html#:~:text=New%20Behavior%20for%20--allow-redefinition
It also requires local_partial_types which could lead to a bunch of new real-positives on older code, but that's now default in mypy 2.0
allow_redefinition is also planned to be turned on by default in an upcoming release, see https://mypy.readthedocs.io/en/stable/config_file.html#confval-allow_redefinition
in other words, the new implementation for mypy allowing redefinition should lead to less false-positives/idiosyncrasies, whilst keeping correctness. And is planned to become the default anyway.
Same change as pypa/distutils@
aacbb3d(#368)This requires the option local_partial_types to also be enabled, but that's default since mypy 2.0