On Wed, Jan 19, 2022 at 07:12:04AM -0500, Ricky Teachey wrote:
> Why does it need to be called at all?
>
> {1, 2, 3}.frozen
For the same reason that most methods are methods, not properties.
The aim of a good API is not to minimize the amount of typing, it is to
communicate the *meaning* of the code as best as possible.
`{1, 2, 3}.frozen` says that the result is an attribute (property,
member) of the set. Like *name* to a person, or *tail* to a dog, the
attribute API represents something which is part of, or a quality of,
the object. The frozenset is not an attribute of the set, it is a
transformation of the set into a different type.
A transformation should be written as an explicit function or method
call, not as attribute access. Yes, we can hide that transformation
behind a property just to save typing two characters, but that is an
abuse of notation.
Also, it is standard in Python to avoid properties if the computation
could be expensive. Copying a large set or millions of elements into a
frozenset could be expensive, so we should keep it a method call.
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/WS5IXNJKETM5JICWCYJPDOF2HNK75DNK/
Code of Conduct: http://python.org/psf/codeofconduct/