Skip to content

Improve error on starred assignment #16287

Description

@ad-chaos

Bug Report

The syntax error message could perhaps be imporved when starred assignments are used incorrectly.

To Reproduce

# test.py
a = *b

Then run

python3 test.py
mypy test.py

Actual Behavior

I'm uncertain on what the expected behaviour should be so I'll just describe the actual behaviour, when running it under python3.11 python produces

File "/private/tmp/test.py", line 1
    a = *b
        ^^
SyntaxError: can't use starred expression here

Whereas mypy says

test.py:1: error: Can use starred expression only as assignment target
Found 1 error in 1 file (errors prevented further checking)

Now, at a glance I thought I can do what I'm doing but it still resulted in an error, also the error seems to indicate that *a = b is fine, but that is incorrect as well.

Your Environment

  • Mypy version used: mypy 1.6.1 (compiled: yes)
  • Mypy command-line flags: --new-type-inference
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11.5

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions