[New-bugs-announce] [issue44703] deepcopy(frozenset()) returns a new object

Svyatoslav report at bugs.python.org
Wed Jul 21 17:20:08 EDT 2021


New submission from Svyatoslav <prometheus3375 at gmail.com>:

from copy import copy, deepcopy
t = 1, 2
t1 = t, 3
t2 = t1, 4
t3 = t2, 5
assert copy(t3) is t3
assert deepcopy(t3) is t3

s = frozenset({1, 2})
assert s.copy() is s  # method .copy() always returns self, what its purpose?
assert copy(s) is s
assert deepcopy(s) is s  # raises AssertionError


Even a deepcopy of a tuple with many nested tuples is the the tuple itself, while a deepcopy of a frozenset which by definition cannot contain mutable objects is a new frozenset.
I think it is an error. A new frozenset is created because deepcopy() fallbacks to pickling.

----------
components: Library (Lib)
messages: 397961
nosy: Prometheus3375
priority: normal
severity: normal
status: open
title: deepcopy(frozenset()) returns a new object
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44703>
_______________________________________


More information about the New-bugs-announce mailing list