Skip to content

Assignment to final variables is allowed in a match statement #19507

@omerhadari

Description

@omerhadari

Bug Report

When matching patterns assignment can override Final variables, and mypy does not report an error.

To Reproduce

from typing import Final
FOO: Final = 8

a = 10

match a:
    case FOO:
        pass
print(FOO)  # FOO is reassigned, prints 10

Expected Behavior

For MyPy to report an error because FOO is final and this assignment should be disallowed.

Actual Behavior

No error is reported
Your Environment

Tested on MacOS and Ubuntu (wsl).

  • Mypy version used: 1.17.0
  • Mypy command-line flags: none
  • Python version used: 3.11.3

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy