Skip to content

Literal idiom for empty set ast.unparse symmetry #150204

@gesslerpd

Description

@gesslerpd

Feature or enhancement

Proposal:

Today, ast.unparse(ast.Set(elts=[])) renders as {*()}, because Python has no dedicated empty-set literal. Without AST canonicalization on parse, reparsing that output produces a Set containing Starred(Tuple([])) instead of an empty Set, so the AST does not round-trip cleanly.

Regardless of decision on PEP 802 this may provide a win for anyone who has already adopted this {*()} idiom.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

Various contributors to the discussion on PEP 802: https://discuss.python.org/t/pep-802-display-syntax-for-the-empty-set/101676

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedtype-featureA feature request or enhancement
    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