Can't deepcopy bytes-derived class
Ned Deily
nad at acm.org
Wed Dec 8 19:11:14 EST 2010
In article <idosir$45i$1 at dough.gmane.org>,
Terry Reedy <tjreedy at udel.edu> wrote:
> On 12/8/2010 2:42 PM, Dan wrote:
> > I have a simple type derived from bytes...
> >
> > class atom(bytes):
> > pass
> >
> > ... that I cannot deepcopy(). The session below demonstrates how
> > deepcopy() of "bytes" works fine, but deepcopy() of "atom" does not.
[...]
> > Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit
> > (Intel)]
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> import copy
> >>>> class atom(bytes):
> > ... pass
> > ...
> >>>> copy.deepcopy(b'abc')
> > b'abc'
> >>>> copy.deepcopy(atom(b'abc'))
> > Traceback (most recent call last):
> > File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver
> > \_sandbox.py", line 1, in<module>
> > # Used internally for debug sandbox under external interpreter
> > File "C:\Python31\Lib\copy.py", line 173, in deepcopy
> > y = _reconstruct(x, rv, 1, memo)
> > File "C:\Python31\Lib\copy.py", line 280, in _reconstruct
> > y = callable(*args)
> > File "C:\Python31\Lib\copyreg.py", line 88, in __newobj__
> > return cls.__new__(cls, *args)
> > builtins.TypeError: string argument without an encoding
>
> You could trace through copy.py and copyreg.py to see where bytes and
> atom get treated differently.
>
> This might be a bug that should be reported on the tracker, but I do not
> know. Let see what anyone else says.
FWIW, the example still fails with Python 3.1.3 but seems to work OK
with a recent alpha build of Python 3.2. What specific change might
have fixed it doesn't come immediately to mind.
--
Ned Deily,
nad at acm.org
More information about the Python-list
mailing list