Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deepcopy of functools.partial gives wierd exception #48630

Closed
kfitch mannequin opened this issue Nov 21, 2008 · 3 comments
Closed

Deepcopy of functools.partial gives wierd exception #48630

kfitch mannequin opened this issue Nov 21, 2008 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@kfitch
Copy link
Mannequin

kfitch mannequin commented Nov 21, 2008

BPO 4380
Nosy @ezio-melotti, @florentx

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-12-20.14:27:34.767>
created_at = <Date 2008-11-21.20:20:47.298>
labels = ['type-bug']
title = 'Deepcopy of functools.partial gives wierd exception'
updated_at = <Date 2009-12-20.14:27:34.766>
user = 'https://bugs.python.org/kfitch'

bugs.python.org fields:

activity = <Date 2009-12-20.14:27:34.766>
actor = 'flox'
assignee = 'none'
closed = True
closed_date = <Date 2009-12-20.14:27:34.767>
closer = 'flox'
components = []
creation = <Date 2008-11-21.20:20:47.298>
creator = 'kfitch'
dependencies = []
files = []
hgrepos = []
issue_num = 4380
keywords = []
message_count = 3.0
messages = ['76200', '95724', '95944']
nosy_count = 3.0
nosy_names = ['ezio.melotti', 'kfitch', 'flox']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue4380'
versions = ['Python 2.5']

@kfitch
Copy link
Mannequin Author

kfitch mannequin commented Nov 21, 2008

from functools import partial
from copy import deepcopy

p = partial("Hello world".replace, "world")
p("mom")
p2 = deepcopy(p)

The output I get is:
Hello mom

Followed by:
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/home/kfitch/<ipython console> in <module>()

/usr/lib/python2.5/copy.py in deepcopy(x, memo, _nil)
187 raise Error(
188 "un(deep)copyable object of type
%s" % cls)
--> 189 y = _reconstruct(x, rv, 1, memo)
190
191 memo[d] = y

/usr/lib/python2.5/copy.py in _reconstruct(x, info, deep, memo)
320 if deep:
321 args = deepcopy(args, memo)
--> 322 y = callable(*args)
323 memo[id(x)] = y
324 if listiter is not None:

/usr/lib/python2.5/copy_reg.py in __newobj__(cls, *args)
90
91 def __newobj__(cls, *args):
---> 92 return cls.__new__(cls, *args)
93
94 def _slotnames(cls):

<type 'exceptions.TypeError'>: type 'partial' takes at least one argument

I am not entirely convinced that doing a deepcopy on a partial makes
sense, but I would expect one of:

  1. An explicit exception saying it isn't allowed
  2. Returning the original partial object
  3. An actual copy (should the arguments its storing get deepcopied?)

P.S. This is with 2.5.2 under Linux (Ubuntu 8.04)

@kfitch kfitch mannequin added the type-bug An unexpected behavior, bug, or error label Nov 21, 2008
@florentx
Copy link
Mannequin

florentx mannequin commented Nov 25, 2009

This issue is somewhat related to the same issue with pickle.
See bpo-1398 for the explanation.

@florentx
Copy link
Mannequin

florentx mannequin commented Dec 3, 2009

Already fixed on Python trunk (2.7).
Fixed on branches 3.1 and 3.2, too.

@florentx florentx mannequin closed this as completed Dec 20, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants