From 8e34864c197fe967c47ad4166823f6df6748a9f6 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 5 Nov 2024 23:24:31 -0500 Subject: [PATCH] bt2: remove some unnecessary checks - getting the id from a stream class, stream or event class can't return negative values - getting the trace class from a trace can't return None - getting the stream class from a stream can't return None Change-Id: If797994f4a10072f662c122c15a5081419d9fa3d Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/13502 Reviewed-by: Philippe Proulx --- src/bindings/python/bt2/bt2/event.py | 2 +- src/bindings/python/bt2/bt2/event_class.py | 10 ++++------ src/bindings/python/bt2/bt2/stream.py | 3 +-- src/bindings/python/bt2/bt2/stream_class.py | 14 ++++---------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/bindings/python/bt2/bt2/event.py b/src/bindings/python/bt2/bt2/event.py index d430179c..3a8e82c5 100644 --- a/src/bindings/python/bt2/bt2/event.py +++ b/src/bindings/python/bt2/bt2/event.py @@ -43,7 +43,7 @@ class _EventConst(bt2_object._UniqueObject, collections.abc.Mapping): return self.cls.name @property - def id(self) -> typing.Optional[int]: + def id(self) -> int: return self.cls.id @property diff --git a/src/bindings/python/bt2/bt2/event_class.py b/src/bindings/python/bt2/bt2/event_class.py index e0a8c704..100d6a7a 100644 --- a/src/bindings/python/bt2/bt2/event_class.py +++ b/src/bindings/python/bt2/bt2/event_class.py @@ -67,10 +67,9 @@ class _EventClassConst(bt2_object._SharedObject, bt2_user_attrs._WithUserAttrsCo @property def stream_class(self) -> "bt2_stream_class._StreamClassConst": - sc_ptr = self._borrow_stream_class_ptr(self._ptr) - - if sc_ptr is not None: - return self._stream_class_pycls._create_from_ptr_and_get_ref(sc_ptr) + return self._stream_class_pycls._create_from_ptr_and_get_ref( + self._borrow_stream_class_ptr(self._ptr) + ) @property def name(self) -> typing.Optional[str]: @@ -78,8 +77,7 @@ class _EventClassConst(bt2_object._SharedObject, bt2_user_attrs._WithUserAttrsCo @property def id(self) -> int: - id = native_bt.event_class_get_id(self._ptr) - return id if id >= 0 else None + return native_bt.event_class_get_id(self._ptr) @property def log_level(self) -> typing.Optional[EventClassLogLevel]: diff --git a/src/bindings/python/bt2/bt2/stream.py b/src/bindings/python/bt2/bt2/stream.py index 70eb5b0a..71dafcd5 100644 --- a/src/bindings/python/bt2/bt2/stream.py +++ b/src/bindings/python/bt2/bt2/stream.py @@ -53,8 +53,7 @@ class _StreamConst(bt2_object._SharedObject, bt2_user_attrs._WithUserAttrsConst) @property def id(self) -> int: - id = native_bt.stream_get_id(self._ptr) - return id if id >= 0 else None + return native_bt.stream_get_id(self._ptr) @property def trace(self) -> "bt2_trace._TraceConst": diff --git a/src/bindings/python/bt2/bt2/stream_class.py b/src/bindings/python/bt2/bt2/stream_class.py index 725b893d..77c4ae79 100644 --- a/src/bindings/python/bt2/bt2/stream_class.py +++ b/src/bindings/python/bt2/bt2/stream_class.py @@ -91,10 +91,9 @@ class _StreamClassConst( @property def trace_class(self) -> "bt2_trace_class._TraceClassConst": - tc_ptr = self._borrow_trace_class_ptr(self._ptr) - - if tc_ptr is not None: - return self._trace_class_cls._create_from_ptr_and_get_ref(tc_ptr) + return self._trace_class_cls._create_from_ptr_and_get_ref( + self._borrow_trace_class_ptr(self._ptr) + ) @property def name(self) -> typing.Optional[str]: @@ -144,12 +143,7 @@ class _StreamClassConst( @property def id(self) -> int: - id = native_bt.stream_class_get_id(self._ptr) - - if id < 0: - return - - return id + return native_bt.stream_class_get_id(self._ptr) @property def packet_context_field_class( -- 2.34.1