bt2: value.py: refactor value comparison
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 28 Jun 2019 03:51:24 +0000 (23:51 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 3 Jul 2019 01:31:27 +0000 (21:31 -0400)
commitb00a769cda57085ca9e682b5ed90e0f4f743203a
treed13f6f295f6441cbb2065ecd814fe46c6010325a
parentc2ea62f5c3978874e4a5cf346e476e5fbdbf79de
bt2: value.py: refactor value comparison

Changed:

* Remove _spec_eq() methods: each class implements its own __eq__()
  method directly.

* Do not use native_bt.value_compare(): we never reached that, because
  container value classes (`ArrayValue` and `MapValue`) implement their
  own rich, recursive comparison.

* In _NumericValue._extract_value(), do not check the `_NumericValue`,
  `False`, and `True` special case: check for `BoolValue` and `bool` to
  return a boolean object in those cases.

* In NumericValue.__lt__() and NumericValue.__eq__(), do not check that
  the parameter is a number object: self._extract_value() does this
  already.

* In BoolValue._value_to_bool(), return the boolean value directly,
  not using int(): it's already an integral number.

* In ArrayValue.__eq__(), be more strict: expect that the parameter is
  a sequence object, not just an iterable object. Before this, it was
  possible to compare an array value to an ordered dict with keys equal
  to the array value content, and this seems wrong as:

      collections.OrderedDict((('A', 23), ('B', 42))) == ['A', 'B']

  is false. An ordered dict is not a sequence.

* In MapValue.__eq__(), be more strict: expect that the parameter is a
  mapping object, not just an iterable and indexable object. The reason
  is similar to the ArrayValue.__eq__() case above. This should be
  enough to compare to another map value or to a dict (or ordered dict).

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9941d2d82942e2efa8d5380c8ff5a4a2d2cb3a84
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1563
Tested-by: jenkins <jenkins@lttng.org>
src/bindings/python/bt2/bt2/value.py
This page took 0.025242 seconds and 4 git commands to generate.