Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Can't assign to () #5594

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions