[issue4380] Deepcopy of functools.partial gives wierd exception

2008-11-21 Thread Kevin Fitch

New submission from Kevin Fitch [EMAIL PROTECTED]:

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)

--
messages: 76200
nosy: kfitch
severity: normal
status: open
title: Deepcopy of functools.partial gives wierd exception
type: behavior
versions: Python 2.5

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4380
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4381] Cannot declare multiple classes via exec when inside a function.

2008-11-21 Thread Kevin Fitch

New submission from Kevin Fitch [EMAIL PROTECTED]:

codeText = 
class foo(object): pass
class bar(object):
  baz = foo()


def doExec(text):
  exec text

### This works:
# Although if I do this before the doExec below, then the
# doExec doesn't fail.
# exec codeText

### But this does not:
doExec(codeText)


The output I get is:
---
type 'exceptions.NameError' Traceback (most recent call last)

/home/kfitch/ipython console in module()

/home/kfitch/ipython console in doExec(text)

/home/kfitch/string in module()

/home/kfitch/string in bar()

type 'exceptions.NameError': name 'foo' is not defined



I don't fully understand why the version in the function doesn't work,
but I suspect it is a bug related to scoping, since foo is really
doExec.foo (I think).

This is with python 2.5.2 under Linux (Ubuntu 8.04)

--
messages: 76202
nosy: kfitch
severity: normal
status: open
title: Cannot declare multiple classes via exec when inside a function.
versions: Python 2.5

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4381
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com