deepcopy raises TypeError for method/function?

From: OKB (not okblacke) (BrenBarn_at_aol.com)
Date: 09/09/04


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


Relevant Pages

  • Re: book most read by Americans
    ... >> I'm guessing you're restricting this to books authored by humans..i.e.you're ... >> excluding the bible. ... > So you're saying the bible was authored by sub-humans? ...
    (rec.arts.books)
  • Re: Todays quiz
    ... I'm guessing it has something to do with David and Posh, ... times and don't know what he is saying. ... his commercial value to his employers, curtailing the relevance of all the ...
    (rec.gambling.poker)
  • Re: Paging any migraine sufferers. Got a good relief tip?
    ... drugs began to take hold. ... I remember Champ saying ... (I'm guessing) ...
    (uk.rec.motorcycles)
  • Re: Help check my proof please?
    ... I'm guessing, you've seen my work, maybe you ... can figure out my skill level by it. ... make a program work. ... your saying the same thing I said. ...
    (sci.math)