bt2: field.py: numeric classes: remove __i*__ operators
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 28 Jun 2019 05:03:18 +0000 (01:03 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 3 Jul 2019 01:31:27 +0000 (21:31 -0400)
commit3dc0614bb91af3ef70b5f5414318e5f2e052e582
tree419bc58b57f7832e5fd7c493a100010072be29c0
parente502b15acf555af2b6f5c43c1ab1876e816c45f9
bt2: field.py: numeric classes: remove __i*__ operators

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

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

    my_int_field += 17.5

and that, when the value of `my_int_field` was 23, its value after the
operation 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 field object: this is internal Python's
magic.

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

    my_int_field += 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 field
object becomes conceptually frozen as soon as you emit a message which
owns it indirectly, there's no point in doing `+=`, `-=`, `**=`, `<<=`,
and so on. For those rare cases, you can always do:

    my_int_field = my_int_field + 17

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I5410ff8fdb2c3a1910e788542376d521601fdf8f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1568
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/field.py
tests/bindings/python/bt2/test_field.py
This page took 0.025802 seconds and 4 git commands to generate.