Skip to content

Some invalid star expressions do not give syntax errors #19077

@MeGaGiGaGon

Description

@MeGaGiGaGon

Summary

I noticed some invalid star expressions do not give a SyntaxError. I tested all I could think of, but I might have missed some cases. I also tested if they fail in ast.parse or only in exec, since I think that affects where the SyntaxError should be raised from.
https://play.ruff.rs/140067c2-f088-4992-847a-26a6652cc88e

# SyntaxError: Starred expression cannot be used here
(*
*[],)

# No error
# Should give SyntaxError: Invalid star expression
# Fails in ast.parse
print(*
*[])

# No error
# Should give SyntaxError: can't use starred expression here
# Passes ast.parse, fails in exec
f"{*[]}"

# No error
# Should give SyntaxError: starred assignment target must be in a list or tuple
# Passes ast.parse, fails in exec
for *a in []:...

Version

playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparserRelated to the parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions