Skip to content

mypy: allow_redefinition = true#203

Open
Avasam wants to merge 1 commit into
jaraco:mainfrom
Avasam:mypy--allow_redefinition-=-true
Open

mypy: allow_redefinition = true#203
Avasam wants to merge 1 commit into
jaraco:mainfrom
Avasam:mypy--allow_redefinition-=-true

Conversation

@Avasam

@Avasam Avasam commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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

Comment thread pyproject.toml
Comment on lines -77 to -78
[tool.pytest-enabler.mypy]
# Disabled due to jaraco/skeleton#143

@Avasam Avasam Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a PR open for most if not all. Issue is also now closed.

@Avasam
Avasam force-pushed the mypy--allow_redefinition-=-true branch from 8309735 to e935449 Compare July 10, 2026 20:49
@Avasam Avasam mentioned this pull request Jul 10, 2026
Comment thread mypy.ini
# Is the project well-typed?
strict = False
# More lenient, but still safe, reassignments
allow_redefinition = true

@jaraco jaraco Jul 12, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@Avasam Avasam Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants