[docs] frozenset.copy() does not create a copy
INADA Naoki
songofacandy at gmail.com
Tue May 8 04:28:12 EDT 2018
On Tue, May 8, 2018 at 5:20 PM Mihail Temelkov <mtemelkov at gmail.com> wrote:
> Tried it in Python 2.7 and found that it just creates an alias to the
original set.
In Python, copy() or similar methods may return itself for immutable types.
It's widely used optimization.
>>> t=(1,2)
>>> t1=(1,2)
>>> t2=t1[:]
>>> t1 is t2
True
And it is implementation (CPython) specific optimization; other
implementation
may return new instance.
You shouldn't rely on undocumented behavior.
Regards,
--
INADA Naoki <songofacandy at gmail.com>
More information about the docs
mailing list