Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error on starred assignment #16287

Closed
ad-chaos opened this issue Oct 18, 2023 · 2 comments · Fixed by #16304
Closed

Improve error on starred assignment #16287

ad-chaos opened this issue Oct 18, 2023 · 2 comments · Fixed by #16304
Labels
bug mypy got something wrong good-first-issue topic-error-reporting How we report errors topic-usability

Comments

@ad-chaos
Copy link

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
@ad-chaos ad-chaos added the bug mypy got something wrong label Oct 18, 2023
@JelleZijlstra
Copy link
Member

Thanks for the report! I would suggest we simply copy CPython's error message "can't use starred expression here".

@parasiitism
Copy link

Could you please consider assigning this issue to me? I am enthusiastic about getting involved in the project and am eager to collaborate with your team to help address this matter.

hauntsaninja pushed a commit that referenced this issue Oct 27, 2023
Fixes #16287

Update mypy's error on starred expression to match that of Python 3.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong good-first-issue topic-error-reporting How we report errors topic-usability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants