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
Currently the AST doesn't allow
frozendictas constants when compiled:This is implemented for
frozensetso it makes sense to do the same for
frozendict.Linked PRs
frozendictsupport to the compiler and AST constants #150050