Implementing a property using the double asterisk (**)
<p>Following <a href="http://www.programiz.com/python-programming/property" rel="nofollow">http://www.programiz.com/python-programming/property</a>, I'm familiar with the following method of implementing a property in Python:</p>

<pre><code>class Celsius(object):
    def __init__(self, temperature = 0):
        self._temperature = temperature

    def get_temperature(self):
        print("Getting value")
        return self._temperature

    def set_temperature(self, value):
        if value &lt; -273:
            raise ValueError("Temperature below -273 is not possible")
        print("Setting value")
        self._temperature = value

    temperature = property(get_temperature, set_temperature)
</code></pre>

<p>I'm now reading some code in which the double asterisk (<code>**</code>) is used in defining the property. If I adapt it to my own example, it seems to be like this:</p>

<pre><code>class Celsius(object):
    def __init__(self, temperature = 0):
        self._temperature = temperature

    def temperature():
        def fget(self):
            print("Getting value")
            return self._temperature
        def fset(self, value):
            if value &lt; -273:
                raise ValueError("Temperature below -273 is not possible")
            print("Setting value")
            self._temperature = value

    temperature = property(**temperature())
</code></pre>

<p>However, if I try to run this code and instantiate a class through <code>c = Celsius()</code>, I get</p>

<pre><code>TypeError: type object argument after ** must be a mapping, not NoneType
</code></pre>

<p>I understand that <code>fget</code> and <code>fset</code> are keyword arguments of <code>property</code>, so I would expect what comes out of <code>**temperature()</code> to be something like <code>fget=fget, fset=fset</code>, but I am not sure what is going wrong here or how to dissect it further. Any ideas?</p>

<p>You should <code>return</code> the nested functions and then unpack them according from the function call:</p>

<pre><code>class Celsius(object):
    def __init__(self, temperature = 0):
        self._temperature = temperature

    def temperature():
        ...
        return fget, fset

    temperature = property(*temperature())
</code></pre>

<p>If you insist on using <code>**</code>, then you'll be returning a mapping/dictionary from your function which will then be <em>unpacked</em> as keyword arguments.</p>

<pre><code>def temperature():
    ...
    return {'fget': fget, 'fset': fset}

temperature = property(**temperature())
</code></pre>

python properties