deepcopy raises TypeError for method/function?
From: OKB (not okblacke) (BrenBarn_at_aol.com)
Date: 09/09/04
- Next message: marduk: "Re: Is except: ... pass bad style?"
- Previous message: Steve Christensen: "Re: popen pipes fail when cwd is a UNC path"
- Next in thread: Alex Martelli: "Re: deepcopy raises TypeError for method/function?"
- Reply: Alex Martelli: "Re: deepcopy raises TypeError for method/function?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Sep 2004 17:58:56 GMT
I've noticed some peculiar behavior from copy.deepcopy: if you pass
it a method or function object, it raises a TypeError somewhere in
copy_reg saying "function() takes at least 2 arguments (0 given)". I'm
guessing this is the constructor for functions, and it's somehow being
incorrectly called, but I'm not really sure.
This behavior is annoying, however. I realize the deepcopy
documentation warns that it doesn't handle copying certain things, but
its behavior when asked to copy those things varies. For instance,
deepcopy(SomeClass) just silently returns the same SomeClass object. I
would expect deepcopy(someObj.someMethod) to do likewise, just returning
the same method object.
Does anyone have any pointers on this? It seems that certain types
are safe to deepcopy (even if they're not actually copied) whereas
others are not. Do I just have to manually typecheck for functions and
methods? Are there any other types that might raise such an error?
-- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown
- Next message: marduk: "Re: Is except: ... pass bad style?"
- Previous message: Steve Christensen: "Re: popen pipes fail when cwd is a UNC path"
- Next in thread: Alex Martelli: "Re: deepcopy raises TypeError for method/function?"
- Reply: Alex Martelli: "Re: deepcopy raises TypeError for method/function?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|