Skip to content

Can't assign to () #5594

@tyehle

Description

@tyehle

Mypy incorrectly complains about assignments to (). The simplest example of this is

() = []

This code executes without a problem, but mypy says error: can't assign to ()

A more real world use case might be code like this

(a, b), () = [[1, 2], []]

In this case the assignment to () is a concise way of asserting that the second list is empty.

  • What is the actual behavior/output?
    error: can't assign to ()
  • What is the behavior/output you expect?
    No type checking errors
  • What are the versions of mypy and Python you are using?
    A build from the latest commit as of writing this, 614090b
  • What are the mypy flags you are using?
    No flags

If this is a change you decide would be good then I believe it could be implemented by removing the the check on line 1930 of mypy/semanal.py and updating the tests.

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