Skip to content

method_cache causes AttributeError when deepcopying object #3

@jaraco

Description

@jaraco

In #2, the deepcopy test is revealing that the fix for deepcopying an lru_cache was not sufficient to fully restore the ability to deep copy a method_cache-instrumented object. Failure is thus:

_________________________________ TestMethodCache.test_deepcopy __________________________________

self = <test_functools.TestMethodCache object at 0x103e74780>

    @pytest.mark.skipif(bad_vers, reason="https://bugs.python.org/issue25447")
    def test_deepcopy(self):
            """
            A deepcopy of an object with a method cache should still
            succeed.
            """

            ob = ClassUnderTest()
            copy.deepcopy(ob)
            ob.method(1)
>           copy.deepcopy(ob)

test_functools.py:77: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py:182: in deepcopy
    y = _reconstruct(x, rv, 1, memo)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py:298: in _reconstruct
    state = deepcopy(state, memo)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py:155: in deepcopy
    y = copier(x, memo)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py:244: in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

x = <functools._lru_cache_wrapper object at 0x103443f60>
memo = {4353936328: {}, 4360456624: <test_functools.ClassUnderTest object at 0x103e07048>}
_nil = []

    def deepcopy(x, memo=None, _nil=[]):
        """Deep copy operation on arbitrary Python objects.

        See the module's __doc__ string for more info.
        """

        if memo is None:
            memo = {}

        d = id(x)
        y = memo.get(d, _nil)
        if y is not _nil:
            return y

        cls = type(x)

        copier = _deepcopy_dispatch.get(cls)
        if copier:
            y = copier(x, memo)
        else:
            try:
                issc = issubclass(cls, type)
            except TypeError: # cls is not a class (old Boost; see SF #502085)
                issc = 0
            if issc:
                y = _deepcopy_atomic(x, memo)
            else:
                copier = getattr(x, "__deepcopy__", None)
                if copier:
                    y = copier(memo)
                else:
                    reductor = dispatch_table.get(cls)
                    if reductor:
                        rv = reductor(x)
                    else:
                        reductor = getattr(x, "__reduce_ex__", None)
                        if reductor:
>                           rv = reductor(4)
E                           AttributeError: 'functools._lru_cache_wrapper' object has no attribute '__qualname__'

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copy.py:174: AttributeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions