Skip to content

Add support for frozendict as AST Constant #150045

@lgeiger

Description

@lgeiger

Currently the AST doesn't allow frozendict as constants when compiled:

import ast
node = ast.Expression(body=ast.Constant(value=frozendict({"a": 1})))
compile(ast.fix_missing_locations(node), "<string>", "eval")
Traceback (most recent call last):
  File "<python-input-0>", line 4, in <module>
    compile(ast.fix_missing_locations(node), "<string>", "eval")
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: got an invalid type in Constant: frozendict

This is implemented for frozenset

node = ast.Expression(body=ast.Constant(value=frozenset({"a", "b"})))
compile(ast.fix_missing_locations(node), "<string>", "eval")
<code object <module> at 0x1067203b0, file "<string>", line 1>

so it makes sense to do the same for frozendict.

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions