Skip to content

The "dummy" variable _ is type-checked in assignments #19488

@ChVeen

Description

@ChVeen

Bug Report
If the "dummy" variable _ is used several times in assignments as shown in the following code snippet, we get an error, because different expressions return different types.
IMHO, this _ variable shouldn't be checked for typing in assignments, because it is freely used to throw away all types of returned results.

To Reproduce

def f1() -> int:
    return 5

def f2() -> str:
    return "5"

_ = f1()
_ = f2()

Expected Behavior
No error message.

Actual Behavior

mypy-test.py:8: error: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.17.0
  • Python version used: 3.10.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    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