Martin v. Loewis wrote:
Because you cannot modify their state.
same thing as tuples: you cannot modify the tuples, but you can modify their members. as its name implies, deepcopy can deal with tuples...
So you'd have to modify a, to modify m.group(0). To catch this case, you might want to do
def copy_match(m): g = m.group(0) if copy(g) is not g: raise KeyError # will be re-raised as copy.Error return g
That will restore backwards compatibility with pre, which is what the submitter of the bug requested.
which means that deepcopy sometimes work on match objects, and sometimes doesn't. *that* sounds like a bug to me. frankly, I don't think the original problem is a bug at all -- I think someone's abusing a CPython 1.5.2 implementation detail. it's not documented to work, it's not in the test suite, and it's not exactly the only thing in there that cannot be deepcopied... introducing broken behaviour to deal with someone's broken program sounds like a rather lousy idea -- and a dangerous precedent. user code shouldn't depend on accidental implementation details. Cheers /F