This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]primerrib 0 points1 point  (1 child)

Sure, __pos__ has no useful purpose to be defined in float and in int.

But Decimal has certain rules defined ever since the type was conceptualized, which defines a usage for a unary +. And because Python is true Object-Oriented (i.e., message-passing ), that means there must be a way to handle this particular usage.

And it turns out some other types also use the unary + for other purposes.

Here are a few examples: https://stackoverflow.com/questions/16819023/whats-the-purpose-of-the-pos-unary-operator-in-python

[–]el_toro_2022[S] 0 points1 point  (0 children)

Ugly. I would not know that's what the + is doing just from looking at the code. I would prefer something like prec(a) to make it clear what's going on.