Can't deepcopy bytes-derived class
Terry Reedy
tjreedy at udel.edu
Wed Dec 8 16:16:11 EST 2010
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.
> What's going wrong?
>
> Thanks,
> Dan.
>
>
> 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.
--
Terry Jan Reedy
More information about the Python-list
mailing list