PEP 802: Display Syntax for the Empty Set

Essentially, this kind of discussion of/ as a syntactic pseudo-expression in an expression list is the generalization of the {/} syntax. But I don’t think / is appropriate in this case.

pass

If we’re going down that route we might as well make pass an expression which skips part of the expression list inside literals:

condition = ...
my_tuple1 = tuple(filter(None, (
    "first_item",
    "second_item" if condition else None,
    "third_item",
)))    # Current syntax requires a filter
my_tuple2 = (
    "first_item",
    "second_item" if condition else pass,
    "third_item",
)

# Type checkers will have knowledge of how many items there are statically
if condition:
    assert_type(my_tuple2, tuple[str, str, str])
else:
    assert_type(my_tuple2, tuple[str, str])

# Examples with sets and dicts
my_empty_set = {pass}    
my_empty_dict = {pass: pass}    # The pair is skipped if either key or value is pass

Outside literals, pass can only appear in an expression statement by itself, i.e. behaves the same as the pass statement now.

If such alternate proposals are developed then I don’t think OP’s PEP will be necessary.

1 Like