Skip to content

Cache constant frozen-sets #2741

Open
@scoder

Description

@scoder

Some set constants can be replaced by frozensets, e.g. in cases like x in {1,2,3}. This would allow them to become global constants, created once at module init time. There is already a framework for merging tuple and string constants, see TupleNode. The ConstantFolding transformation could detect these cases and set a flag attribute on the SetNode instances that would trigger constant frozenset behaviour.

Other potential candidates:

>>> frozenset((1,2,3)) | {2,3,4}  # imagine one side being non-constant
frozenset([1, 2, 3, 4])
>>> {3,4,5} | frozenset((1,2,3))
set([1, 2, 3, 4, 5])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions