When one needs a custom property, the easy, readable, and that already works way to create then
is just to create an instance of the their class and assign the instance to the desired
class attribute. All the class have to do is to have the methods that identify it as a descriptor: "__get__" and "__set__" for
data descriptors , and optionally "__del__". 

The class can be made in a way to make it easier to write the setters and getter , and have
their "__set__" and "__get__" call these other methods, but that is about it.
```
class ThresholdProperty:

    def __init__(self, threshold=0.5):
         self.threshold = threshold
    def __set_name__(self, owner, name):
         self.name = name
    def __set__(self, instance, value):
          self.instance.setattr("_" + self.name, value)
    def __get__(self, instance, owner):
         if instance is None: return self
         return int(getattr(instance, "_" + self.name) > self.threshold)

class Neuron:
   activation = ThresholdProperty()

```

On Tue, 4 Aug 2020 at 05:16, Chris Angelico <rosuav@gmail.com> wrote:
On Tue, Aug 4, 2020 at 6:09 PM <redradist@gmail.com> wrote:
>
> Hi all,
>
> Seems like this topic was previously raised, but what if we add possibility to decorate non function properties in class:
>
> ```python
> class Neuron:
>     @linear_activation
>     activation
> ```

What would that decoration do, exactly?

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/V3HHI4FZZBRBX6FB6246342HYDDFDXJT/
Code of Conduct: http://python.org/psf/codeofconduct/