What is the python equivalent of c++ const-reference copy-constructor arguments
<p>One of the great things of C++ is the usage of <code>const</code>-reference arguments â using these type of argument, you're pretty much guaranteed objects wonât be accidentally modified, and there wonât be side effects.</p>

<p>Question is, whatâd be the Python equivalent to such arguments?</p>

<p>For instance, letâs say you have this C++ method:</p>

<pre><code>void Foo::setPosition(const QPoint &amp;position) {
    m_position = position;
}
</code></pre>

<p>And you want to âtranslateâ it to Python like this:</p>

<pre><code>def set_position(self, position):
    self.position = position
</code></pre>

<p>Doing this will potentially yield a lot of trouble, and many subtle bugs could appear as well. Question is, whatâs the âPython equivalentâ way of C++ methods which use const references arguments (copy constructor)?</p>

<p>Last time I caught a bug because a I had a bad âC++ -> Python translationâ; I fixed this with something like:</p>

<pre><code>my_python_instance.set_position(QPoint(pos))
</code></pre>

<p>â¦ said otherwise, my other choice was to clone the object from the callerâ¦ which Iâm pretty much sure is not the right way to go.</p>

<p>There is no direct equivalent. The closest is to use the <a href="https://docs.python.org/2/library/copy.html" rel="nofollow"><code>copy</code> module</a> and define the <code>__copy__()</code> and/or <code>__deepcopy__()</code> methods on your classes.</p>

python c++ language-lawyer copy-constructor const-correctness