From 9fe6b412211ae62af97737f5d7e77131be37199b Mon Sep 17 00:00:00 2001 From: Alex Martelli Date: Sun, 6 Feb 2005 07:56:18 +0000 Subject: [PATCH] fix bug 1114776 --- Lib/copy.py | 3 ++- Lib/test/test_copy.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Lib/copy.py b/Lib/copy.py index 95e30f5231cf..7771ef03e8b6 100644 --- a/Lib/copy.py +++ b/Lib/copy.py @@ -62,8 +62,9 @@ except ImportError: __all__ = ["Error", "copy", "deepcopy"] +import inspect def _getspecial(cls, name): - for basecls in cls.__mro__: + for basecls in inspect.getmro(cls): try: return basecls.__dict__[name] except: diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 3484fa77dd5e..8ad5c8511f32 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -222,6 +222,23 @@ class TestCopy(unittest.TestCase): x = C(23) self.assertEqual(copy.deepcopy(x), x) + def _nomro(self): + class C(type): + def __getattribute__(self, attr): + if attr == '__mro__': + raise AttributeError, "What, *me*, a __mro__? Nevah!" + return super(C, self).__getattribute__(attr) + class D(object): + __metaclass__ = C + return D() + + def test_copy_mro(self): + x = self._nomro() + y = copy.copy(x) + + def test_deepcopy_mro(self): + x = self._nomro() + y = copy.deepcopy(x) # The deepcopy() method def test_deepcopy_basic(self): -- 2.47.3