Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

Python Setter throws Type Error. What is wrong here?

$
0
0

I have a dataclass with an attribute 'open' of type float.I added a property setter which shall throw a ValueError in case it gets set to a negative value:

@open.setterdef open(self, value: float) -> None:    if value < 0.0:        raise ValueError("Open value must be positive.")    self.open = value

The error I am getting is:

File "<string>", line 4, in __init__  File "/home/PATH/file.py", line 29, in open    if value < 0.0:       ^^^^^^^^^^^  TypeError: '<' not supported between instances of 'property' and 'float'

I don't really get what I am doing wrong here.Thanks for any advice!


Viewing all articles
Browse latest Browse all 11661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>