bt2: value.py: numeric classes: remove __i*__ operators
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 28 Jun 2019 04:32:14 +0000 (00:32 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 18 Jul 2019 15:53:33 +0000 (11:53 -0400)
commitd79a9f23979db0b733be95e4b56da3911e56c0a9
tree89e9e5565b0cc84d7035fb110b8081842ca1d61c
parent4c485b227412fb8078e204108be733e16f816dec
bt2: value.py: numeric classes: remove __i*__ operators

Those operators do a binary operation to a value object and another
operand, and then set the result as the value object's value.

Now that I think about it, it is weird to do something like:

    a = bt2.UnsignedIntegerValue(23)
    a += 17.5

and that the value of `a` becomes 40. This is not a problem for a native
Python object because `a` does not name the same object after the
operation:

    a = 23
    type(a)     # int
    id(a)       # 140669243488160
    a += 17.5
    type(a)     # float
    id(a)       # 140669043054920

but we can't do this with our value object: this is internal Python's
magic.

So I believe we should be more strict. But this means you can't do:

    a = bt2.UnsignedIntegerValue(23)
    a += 17.5

anymore (a `TypeError` exception would be raised).

This means a lot of specific automatically injected tests must
conditionally exist (depending on whether or not the test is possible
with the two operands, whereas it's always possible now).

Instead of doing this work, I choose to completely remove the support
for "self" operators. We can add useful ones in the future when we have
time, but I don't even think they are super useful: because a value
object becomes conceptually frozen as soon as you use it somehow,
there's no point in doing `+=`, `-=`, `**=`, `<<=`, and so on. For those
rare cases, you can always do:

    a = bt2.UnsignedIntegerValue(23)
    a = a + 17

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Icd5f0a9d0232c2f7ba91133561235fec7526083b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1566
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/bindings/python/bt2/bt2/value.py
tests/bindings/python/bt2/test_value.py
This page took 0.026429 seconds and 4 git commands to generate.