The pyright static type checker doesn't like for these methods in
_SharedObject:
@staticmethod
def _get_ref(ptr):
raise NotImplementedError
@staticmethod
def _put_ref(ptr):
raise NotImplementedError
... to be overriden by assignment like this:
_get_ref = staticmethod(native_bt.field_class_get_ref)
_put_ref = staticmethod(native_bt.field_class_put_ref)
The warnings it gives are:
/home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py
/home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:48:16 - error: Expression of type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to declared type "(ptr: Unknown) -> Unknown"
Type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to type "(ptr: Unknown) -> Unknown"
Parameter name mismatch: "ptr" versus "field_class" (reportGeneralTypeIssues)
/home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:49:16 - error: Expression of type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to declared type "(ptr: Unknown) -> Unknown"
Type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to type "(ptr: Unknown) -> Unknown"
Parameter name mismatch: "ptr" versus "field_class" (reportGeneralTypeIssues)
So, it's just the parameter name that it doesn't like. The obvious
solution would be to rename the `ptr` parameters of
_SharedObject._{get,put}_ref to `field_class`, in _SharedObject, to
match the names in native_bt.py. However, I don't want us to be tied to
the names in native_bt.py (which originally come from the C header
files), as in Python we often want to use `ptr` in the name to
differentiate the SWIG wrapper around the pointer and the higher-level.
Another solution might be to use SWIG code to rename function parameters
in the SWIG-generated code, but I'm not so well-versed in SWIG, I
couldn't find how to do that.
So, I propose to just use the standard syntax for methods instead, the
type checker seems to be happy with that.
Change-Id: Ife5ad007aea4fb315d3ff4f8da67c48f4bf3e96d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10240
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
19 files changed:
class _ClockClassConst(object._SharedObject):
class _ClockClassConst(object._SharedObject):
- _get_ref = staticmethod(native_bt.clock_class_get_ref)
- _put_ref = staticmethod(native_bt.clock_class_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.clock_class_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.clock_class_put_ref(ptr)
+
_create_value_from_ptr_and_get_ref = staticmethod(
bt2_value._create_from_const_ptr_and_get_ref
)
_create_value_from_ptr_and_get_ref = staticmethod(
bt2_value._create_from_const_ptr_and_get_ref
)
class _SourceComponentClassConst(_ComponentClassConst):
class _SourceComponentClassConst(_ComponentClassConst):
- _get_ref = staticmethod(native_bt.component_class_source_get_ref)
- _put_ref = staticmethod(native_bt.component_class_source_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.component_class_source_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.component_class_source_put_ref(ptr)
+
_bt_as_component_class_ptr = staticmethod(
native_bt.component_class_source_as_component_class
)
class _FilterComponentClassConst(_ComponentClassConst):
_bt_as_component_class_ptr = staticmethod(
native_bt.component_class_source_as_component_class
)
class _FilterComponentClassConst(_ComponentClassConst):
- _get_ref = staticmethod(native_bt.component_class_filter_get_ref)
- _put_ref = staticmethod(native_bt.component_class_filter_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.component_class_filter_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.component_class_filter_put_ref(ptr)
+
_bt_as_component_class_ptr = staticmethod(
native_bt.component_class_filter_as_component_class
)
class _SinkComponentClassConst(_ComponentClassConst):
_bt_as_component_class_ptr = staticmethod(
native_bt.component_class_filter_as_component_class
)
class _SinkComponentClassConst(_ComponentClassConst):
- _get_ref = staticmethod(native_bt.component_class_sink_get_ref)
- _put_ref = staticmethod(native_bt.component_class_sink_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.component_class_sink_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.component_class_sink_put_ref(ptr)
+
_bt_as_component_class_ptr = staticmethod(
native_bt.component_class_sink_as_component_class
)
_bt_as_component_class_ptr = staticmethod(
native_bt.component_class_sink_as_component_class
)
# This is analogous to _SourceComponentClassConst, but for source
# component objects.
class _GenericSourceComponentConst(object._SharedObject, _SourceComponentConst):
# This is analogous to _SourceComponentClassConst, but for source
# component objects.
class _GenericSourceComponentConst(object._SharedObject, _SourceComponentConst):
- _get_ref = staticmethod(native_bt.component_source_get_ref)
- _put_ref = staticmethod(native_bt.component_source_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.component_source_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.component_source_put_ref(ptr)
@property
def output_ports(self):
@property
def output_ports(self):
# This is analogous to _FilterComponentClassConst, but for filter
# component objects.
class _GenericFilterComponentConst(object._SharedObject, _FilterComponentConst):
# This is analogous to _FilterComponentClassConst, but for filter
# component objects.
class _GenericFilterComponentConst(object._SharedObject, _FilterComponentConst):
- _get_ref = staticmethod(native_bt.component_filter_get_ref)
- _put_ref = staticmethod(native_bt.component_filter_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.component_filter_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.component_filter_put_ref(ptr)
@property
def output_ports(self):
@property
def output_ports(self):
# This is analogous to _SinkComponentClassConst, but for sink
# component objects.
class _GenericSinkComponentConst(object._SharedObject, _SinkComponentConst):
# This is analogous to _SinkComponentClassConst, but for sink
# component objects.
class _GenericSinkComponentConst(object._SharedObject, _SinkComponentConst):
- _get_ref = staticmethod(native_bt.component_sink_get_ref)
- _put_ref = staticmethod(native_bt.component_sink_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.component_sink_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.component_sink_put_ref(ptr)
@property
def input_ports(self):
@property
def input_ports(self):
class _ConnectionConst(bt2_object._SharedObject):
class _ConnectionConst(bt2_object._SharedObject):
- _get_ref = staticmethod(native_bt.connection_get_ref)
- _put_ref = staticmethod(native_bt.connection_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.connection_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.connection_put_ref(ptr)
@property
def downstream_port(self):
@property
def downstream_port(self):
class _EventClassConst(object._SharedObject):
class _EventClassConst(object._SharedObject):
- _get_ref = staticmethod(native_bt.event_class_get_ref)
- _put_ref = staticmethod(native_bt.event_class_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.event_class_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.event_class_put_ref(ptr)
+
_borrow_stream_class_ptr = staticmethod(
native_bt.event_class_borrow_stream_class_const
)
_borrow_stream_class_ptr = staticmethod(
native_bt.event_class_borrow_stream_class_const
)
class _FieldClassConst(object._SharedObject):
class _FieldClassConst(object._SharedObject):
- _get_ref = staticmethod(native_bt.field_class_get_ref)
- _put_ref = staticmethod(native_bt.field_class_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.field_class_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.field_class_put_ref(ptr)
+
_borrow_user_attributes_ptr = staticmethod(
native_bt.field_class_borrow_user_attributes_const
)
_borrow_user_attributes_ptr = staticmethod(
native_bt.field_class_borrow_user_attributes_const
)
class _FieldPathConst(object._SharedObject, collections.abc.Iterable):
class _FieldPathConst(object._SharedObject, collections.abc.Iterable):
- _get_ref = staticmethod(native_bt.field_path_get_ref)
- _put_ref = staticmethod(native_bt.field_path_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.field_path_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.field_path_put_ref(ptr)
@property
def root_scope(self):
@property
def root_scope(self):
class Graph(object._SharedObject):
class Graph(object._SharedObject):
- _get_ref = staticmethod(native_bt.graph_get_ref)
- _put_ref = staticmethod(native_bt.graph_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.graph_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.graph_put_ref(ptr)
def __init__(self, mip_version=0):
utils._check_uint64(mip_version)
def __init__(self, mip_version=0):
utils._check_uint64(mip_version)
class _SignedIntegerRangeSetConst(_IntegerRangeSetConst):
class _SignedIntegerRangeSetConst(_IntegerRangeSetConst):
- _get_ref = staticmethod(native_bt.integer_range_set_signed_get_ref)
- _put_ref = staticmethod(native_bt.integer_range_set_signed_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.integer_range_set_signed_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.integer_range_set_signed_put_ref(ptr)
+
_as_range_set_ptr = staticmethod(
native_bt.integer_range_set_signed_as_range_set_const
)
_as_range_set_ptr = staticmethod(
native_bt.integer_range_set_signed_as_range_set_const
)
class _UnsignedIntegerRangeSetConst(_IntegerRangeSetConst):
class _UnsignedIntegerRangeSetConst(_IntegerRangeSetConst):
- _get_ref = staticmethod(native_bt.integer_range_set_unsigned_get_ref)
- _put_ref = staticmethod(native_bt.integer_range_set_unsigned_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.integer_range_set_unsigned_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.integer_range_set_unsigned_put_ref(ptr)
+
_as_range_set_ptr = staticmethod(
native_bt.integer_range_set_unsigned_as_range_set_const
)
_as_range_set_ptr = staticmethod(
native_bt.integer_range_set_unsigned_as_range_set_const
)
class Interrupter(object._SharedObject):
class Interrupter(object._SharedObject):
- _get_ref = staticmethod(native_bt.interrupter_get_ref)
- _put_ref = staticmethod(native_bt.interrupter_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.interrupter_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.interrupter_put_ref(ptr)
def __init__(self):
ptr = native_bt.interrupter_create()
def __init__(self):
ptr = native_bt.interrupter_create()
class _MessageConst(object._SharedObject):
class _MessageConst(object._SharedObject):
- _get_ref = staticmethod(native_bt.message_get_ref)
- _put_ref = staticmethod(native_bt.message_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.message_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.message_put_ref(ptr)
@staticmethod
def _check_has_default_clock_class(clock_class):
@staticmethod
def _check_has_default_clock_class(clock_class):
class _UserComponentInputPortMessageIterator(object._SharedObject, _MessageIterator):
class _UserComponentInputPortMessageIterator(object._SharedObject, _MessageIterator):
- _get_ref = staticmethod(native_bt.message_iterator_get_ref)
- _put_ref = staticmethod(native_bt.message_iterator_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.message_iterator_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.message_iterator_put_ref(ptr)
def __init__(self, ptr):
self._current_msgs = []
def __init__(self, ptr):
self._current_msgs = []
class _PacketConst(object._SharedObject):
class _PacketConst(object._SharedObject):
- _get_ref = staticmethod(native_bt.packet_get_ref)
- _put_ref = staticmethod(native_bt.packet_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.packet_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.packet_put_ref(ptr)
+
_borrow_stream_ptr = staticmethod(native_bt.packet_borrow_stream_const)
_borrow_context_field_ptr = staticmethod(
native_bt.packet_borrow_context_field_const
_borrow_stream_ptr = staticmethod(native_bt.packet_borrow_stream_const)
_borrow_context_field_ptr = staticmethod(
native_bt.packet_borrow_context_field_const
class _PluginSet(object._SharedObject, collections.abc.Sequence):
class _PluginSet(object._SharedObject, collections.abc.Sequence):
- _put_ref = staticmethod(native_bt.plugin_set_put_ref)
- _get_ref = staticmethod(native_bt.plugin_set_get_ref)
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.plugin_set_put_ref(ptr)
+
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.plugin_set_get_ref(ptr)
def __len__(self):
count = native_bt.plugin_set_get_plugin_count(self._ptr)
def __len__(self):
count = native_bt.plugin_set_get_plugin_count(self._ptr)
class _Plugin(object._SharedObject):
class _Plugin(object._SharedObject):
- _put_ref = staticmethod(native_bt.plugin_put_ref)
- _get_ref = staticmethod(native_bt.plugin_get_ref)
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.plugin_put_ref(ptr)
+
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.plugin_get_ref(ptr)
@property
def name(self):
@property
def name(self):
class QueryExecutor(object._SharedObject, _QueryExecutorCommon):
class QueryExecutor(object._SharedObject, _QueryExecutorCommon):
- _get_ref = staticmethod(native_bt.query_executor_get_ref)
- _put_ref = staticmethod(native_bt.query_executor_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.query_executor_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.query_executor_put_ref(ptr)
def _as_query_executor_ptr(self):
return self._ptr
def _as_query_executor_ptr(self):
return self._ptr
class _StreamConst(bt2_object._SharedObject):
class _StreamConst(bt2_object._SharedObject):
- _get_ref = staticmethod(native_bt.stream_get_ref)
- _put_ref = staticmethod(native_bt.stream_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.stream_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.stream_put_ref(ptr)
+
_borrow_class_ptr = staticmethod(native_bt.stream_borrow_class_const)
_borrow_user_attributes_ptr = staticmethod(
native_bt.stream_borrow_user_attributes_const
_borrow_class_ptr = staticmethod(native_bt.stream_borrow_class_const)
_borrow_user_attributes_ptr = staticmethod(
native_bt.stream_borrow_user_attributes_const
class _StreamClassConst(object._SharedObject, collections.abc.Mapping):
class _StreamClassConst(object._SharedObject, collections.abc.Mapping):
- _get_ref = staticmethod(native_bt.stream_class_get_ref)
- _put_ref = staticmethod(native_bt.stream_class_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.stream_class_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.stream_class_put_ref(ptr)
+
_borrow_event_class_ptr_by_id = staticmethod(
native_bt.stream_class_borrow_event_class_by_id_const
)
_borrow_event_class_ptr_by_id = staticmethod(
native_bt.stream_class_borrow_event_class_by_id_const
)
class _StreamClass(_StreamClassConst):
class _StreamClass(_StreamClassConst):
- _get_ref = staticmethod(native_bt.stream_class_get_ref)
- _put_ref = staticmethod(native_bt.stream_class_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.stream_class_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.stream_class_put_ref(ptr)
+
_borrow_event_class_ptr_by_id = staticmethod(
native_bt.stream_class_borrow_event_class_by_id
)
_borrow_event_class_ptr_by_id = staticmethod(
native_bt.stream_class_borrow_event_class_by_id
)
class _TraceConst(object._SharedObject, collections.abc.Mapping):
class _TraceConst(object._SharedObject, collections.abc.Mapping):
- _get_ref = staticmethod(native_bt.trace_get_ref)
- _put_ref = staticmethod(native_bt.trace_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.trace_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.trace_put_ref(ptr)
+
_borrow_stream_ptr_by_id = staticmethod(native_bt.trace_borrow_stream_by_id_const)
_borrow_stream_ptr_by_index = staticmethod(
native_bt.trace_borrow_stream_by_index_const
_borrow_stream_ptr_by_id = staticmethod(native_bt.trace_borrow_stream_by_id_const)
_borrow_stream_ptr_by_index = staticmethod(
native_bt.trace_borrow_stream_by_index_const
class _TraceClassConst(object._SharedObject, collections.abc.Mapping):
class _TraceClassConst(object._SharedObject, collections.abc.Mapping):
- _get_ref = staticmethod(native_bt.trace_class_get_ref)
- _put_ref = staticmethod(native_bt.trace_class_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.trace_class_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.trace_class_put_ref(ptr)
+
_borrow_stream_class_ptr_by_index = staticmethod(
native_bt.trace_class_borrow_stream_class_by_index_const
)
_borrow_stream_class_ptr_by_index = staticmethod(
native_bt.trace_class_borrow_stream_class_by_index_const
)
class _ValueConst(object._SharedObject, metaclass=abc.ABCMeta):
class _ValueConst(object._SharedObject, metaclass=abc.ABCMeta):
- _get_ref = staticmethod(native_bt.value_get_ref)
- _put_ref = staticmethod(native_bt.value_put_ref)
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.value_get_ref(ptr)
+
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.value_put_ref(ptr)
+
_create_value_from_ptr = staticmethod(_create_from_const_ptr)
_create_value_from_ptr_and_get_ref = staticmethod(
_create_from_const_ptr_and_get_ref
_create_value_from_ptr = staticmethod(_create_from_const_ptr)
_create_value_from_ptr_and_get_ref = staticmethod(
_create_from_const_ptr_and_get_ref