Is support for __round__() missing at the moment? #13069
-
Hi. I was writing my own class for an RGB color library and decided to define the
Admittedly this is quite trivial and I could very well just write another method for doing this. But I was just wondering if there are plans to add this. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
An RGB value contain three distinct values for the three named colors. |
Beta Was this translation helpful? Give feedback.
-
Did you try adding float function to your class? That's the normal way to allow conversion of a class to float. Once that's there, the round function should work. I'm actually not sure if round functionality is supported or not. |
Beta Was this translation helpful? Give feedback.
@shovnyk
__round__
is not supported. This appears to be a deliberate decision, see e.g. #3610And @andrewleech is correct,
round(x)
implicitly doesfloat(x)
which will callx.__float__
.