The compiler can figure out that the value of
{1, 2, 3}
is a set containing the elements 1, 2 and 3.
The problem with the value of
frozenset({1, 2, 3})
is that the value of frozenset depends on the context. This is because
frozenset = print
is allowed.
According to help(repr):
repr(obj, /)
Return the canonical string representation of the object.
For many object types, including most builtins, eval(repr(obj)) == obj.
Consistency suggests that if
x = f{1, 2, 3}
gives always gives frozenset as the value of x then
repr(x)
should be the string 'f{1, 2, 3}'. At present, I think, repr(x) always returns a literal if it can.
However, changing the repr of frozenset introduces problems of backwards compatibility, particularly in doctests and documentation.
Another way to achieve consistency is to make frozenset a keyword, in the same way that None, True and False are identifiers that are also language keywords.
Both proposals as stated have negative side-effects. I suggest we explore ways of reducing the above and any other side effects.
--
Jonathan