There seem to be two different reasons people want a generic freeze syntax:

1. Making a hashable copy of an arbitrary object

2. Avoiding O(n) rebuilding of literals on every use (a constant for
bytecode, as you put it)

In both 1 and 2, not only the object but all of its children need to be
immutable. For 2, that's the status quo, but for 1 it seems like a bigger
problem.

There is already a solution of sorts for 1: pickle. It may even be more
efficient than a subobject-by-subobject deep freeze since it stores the
result contiguously in RAM. On the other hand it can't share storage with
already-hashable objects.

For the second one, I would rather have an "inline static" syntax
(evaluates to the value of an anonymous global variable that is initialized
on first use), since it would be more broadly useful, and the disadvantages
seem minor. (The disadvantages I see are that it's built per run instead of
per compile, it's theoretically mutable (but mutation would be evident at
the sole use site), and it may use more heap space depending on how
constants are implemented which I don't know.)

As for the syntax... well, backticks, obviously...
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YM3Z2NMM6AZNSZ67KET6QBIBEFRD3WYW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to