[issue18352] collections.Counter with added attributes are not deepcopied properly.

Olivier Gagnon report at bugs.python.org
Wed Jul 10 16:28:35 CEST 2013


Olivier Gagnon added the comment:

The dictionary and the set do not give the freedom to add dynamic attributes to them. I agree that the Counter should have the same behaviour.

However, this will raise the same bug when we inherit from a Counter object.

>>> class mylist(list): pass
... 
>>> l = mylist()
>>> l.foo = "bar"
>>> c = copy.deepcopy(l)
>>> print(c.foo) # prints bar

>>> class myCounter(Counter): pass
... 
>>> original = myCounter()
>>> original.foo = "bar"
>>> c = copy.deepcopy(original)
>>> c.foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'myCounter' object has no attribute 'foo'

The reduction function should still copy every dynamic attribute of the object.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18352>
_______________________________________


More information about the Python-bugs-list mailing list