TypeError: __deepcopy__() takes 1 positional argument but 2 were given error?
<p>I'm doing a deepcopy for a list of objects, but I keep getting following error:</p>

<pre><code>deepcopy __deepcopy__() takes 1 positional argument but 2 were given
</code></pre>

<p>and following traceback:</p>

<pre class="lang-none prettyprint-override"><code>TypeError                                 Traceback (most recent call last)
&lt;ipython-input-4-66b9ee5521c7&gt; in &lt;module&gt;()
      2
      3 import copy
----&gt; 4 regions_copy = copy.deepcopy(regions)
      5 regions[0].A = 15
      6 print(regions[0].A)

/home/michal/Bin/anaconda/envs/tensorflow/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    153     copier = _deepcopy_dispatch.get(cls)
    154     if copier:
--&gt; 155         y = copier(x, memo)
    156     else:
    157         try:

/home/michal/Bin/anaconda/envs/tensorflow/lib/python3.5/copy.py in _deepcopy_list(x, memo)
    216     memo[id(x)] = y
    217     for a in x:
--&gt; 218         y.append(deepcopy(a, memo))
    219     return y
    220 d[list] = _deepcopy_list

/home/michal/Bin/anaconda/envs/tensorflow/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    180                             raise Error(
    181                                 "un(deep)copyable object of type %s" % cls)
--&gt; 182                 y = _reconstruct(x, rv, 1, memo)
    183
    184     # If is its own copy, don't memoize.

/home/michal/Bin/anaconda/envs/tensorflow/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
    295     if state is not None:
    296         if deep:
--&gt; 297             state = deepcopy(state, memo)
    298         if hasattr(y, '__setstate__'):
    299             y.__setstate__(state)

/home/michal/Bin/anaconda/envs/tensorflow/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    153     copier = _deepcopy_dispatch.get(cls)
    154     if copier:
--&gt; 155         y = copier(x, memo)
    156     else:
    157         try:

/home/michal/Bin/anaconda/envs/tensorflow/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
    241     memo[id(x)] = y
    242     for key, value in x.items():
--&gt; 243         y[deepcopy(key, memo)] = deepcopy(value, memo)
    244     return y
    245 d[dict] = _deepcopy_dict

/home/michal/Bin/anaconda/envs/tensorflow/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
    164             copier = getattr(x, "__deepcopy__", None)
    165             if copier:
--&gt; 166                 y = copier(memo)
    167             else:
    168                 reductor = dispatch_table.get(cls)

TypeError: __deepcopy__() takes 1 positional argument but 2 were given
</code></pre>

<p>The problem seems to be also when I copy a single object. Any idea what could be the cause?</p>

<p>I suppose it might be in my class implementation, because deepcopying a list like <code>[object(), object(), object()]</code> is fine. Although that would be very strange...</p>

<p>I found the problem was in fact in the definition of the variable <code>regions</code>. It is a list of classes <code>AreaRegion</code>, which contained assignment into class <code>__dict__</code>:</p>

<pre><code>from matplotlib.path import Path

...

class AreaRegion:

    def __init__(self):
        ...
        self.path = Path(verts, codes, closed=True)
        ...

    ...
</code></pre>

<p>Apparently it didn't like this, so I've moved Path into a getter instead.</p>

python