[Python-bugs-list] [ python-Bugs-746304 ] TypeError raised when deepcopying built-in functions

SourceForge.net noreply@sourceforge.net
Sat, 14 Jun 2003 00:21:12 -0700


Bugs item #746304, was opened at 2003-05-30 21:59
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=746304&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Oktay Safak (oktaysafak)
Assigned to: Nobody/Anonymous (nobody)
Summary: TypeError raised when deepcopying built-in functions

Initial Comment:
>>> import copy
>>> copy.deepcopy(max)

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in ?
    copy.deepcopy(max)
  File "C:\PYTHON23\lib\copy.py", line 205, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "C:\PYTHON23\lib\copy.py", line 336, in _reconstruct
    y = callable(*args)
  File "C:\PYTHON23\Lib\copy_reg.py", line 84, in __newobj__
    return cls.__new__(cls, *args)
TypeError: object.__new__(builtin_function_or_method) is not 
safe, use builtin_function_or_method.__new__()

Steven Taschuk's guess is that all things pickleable should be 
copyable since copy uses the same protocol as pickle. (He is 
not sure though) He demonstrates this idea with the following 
example:

>>> import pickle
>>> pickle.loads(pickle.dumps(max))
<built-in function max>

which succeeds unlike the first example.

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2003-06-14 09:21

Message:
Logged In: YES 
user_id=21627

Thanks for the bugreport. This is now fixed in 

copy.py 1.42
test_copy.py 1.11
NEWS 1.782
copy.py 1.22.10.6
NEWS 1.337.2.4.2.88


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=746304&group_id=5470