Skip to content

[codex] Add walrus allow-redefinition test#21660

Open
EltonChang1 wants to merge 3 commits into
python:masterfrom
EltonChang1:codex/test-walrus-allow-redefinition
Open

[codex] Add walrus allow-redefinition test#21660
EltonChang1 wants to merge 3 commits into
python:masterfrom
EltonChang1:codex/test-walrus-allow-redefinition

Conversation

@EltonChang1

@EltonChang1 EltonChang1 commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Adds focused coverage for #7314 by testing how assignment expressions inside a list comprehension interact with --allow-redefinition.

The new case verifies that the comprehension result is inferred as list[str], that mypy currently keeps the outer variable's revealed type as int after the comprehension, and that a later assignment can still redefine it to float under --allow-redefinition.

Test Plan

  • .venv/bin/python -m pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-redefine2.test -k testNewRedefineAssignmentExpressionComprehensions
  • .venv/bin/python -m pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-redefine2.test

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new unit test intended to cover the interaction between --allow-redefinition and assignment expressions used inside a list-comprehension-like construct, as discussed in #7314.

Changes:

  • Adds a new check-redefine2 test case asserting that a walrus assignment can redefine a local variable’s type under --allow-redefinition.
  • Asserts that a subsequent reassignment can redefine the same variable again to a different type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test-data/unit/check-redefine2.test Outdated
EltonChang1 and others added 2 commits June 30, 2026 03:21
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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