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

SourceForge.net noreply@sourceforge.net
Fri, 30 May 2003 12:59:59 -0700


Bugs item #746304, was opened at 2003-05-30 22:59
Message generated for change (Tracker Item Submitted) made by Item Submitter
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: Open
Resolution: None
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.

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

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