python: define _BaseObject._ptr property
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 12 Jun 2023 20:32:42 +0000 (16:32 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Sat, 19 Oct 2024 11:12:09 +0000 (07:12 -0400)
commit05a32d38d44145b04cd645d824eff230b822672d
tree6db2e1fb506955b4372c6d76dfa4eb7ba7b527f1
parentaccb3c79a4a6fd49479aa262b501e55380dbd9cc
python: define _BaseObject._ptr property

Define the property `_ptr` on _BaseObject, which returns the value of
the currently-named `_ptr` field.  Rename the `_ptr` field to
`_ptr_internal`, for the lack of a better name.

The goal is for mixin classes to be able to declare that they require
such a property to exist, using `abc.abstractmethod`, and for
_BaseObject to fill in the implementation (and for static type checkers
to be happy).  For instance:

    class MyMixin(abc.ABC):
        @property
@abc.abstractmethod
def _ptr(self):
    raise NotImplementedError

def my_method(self):
    ... do something with self._ptr ...

   class MyObject(object._SharedObject, MyMixin):
      ...

In this case, object._SharedObject provides the `_ptr` implementation
that `MyMixin` requires.

Change-Id: I696c04ed690ede7cd50bcb71890cc0b7b25f44e4
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10326
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/bindings/python/bt2/bt2/object.py
This page took 0.025362 seconds and 4 git commands to generate.