bt2: remove some unnecessary checks
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 6 Nov 2024 04:24:31 +0000 (23:24 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 7 Nov 2024 21:03:40 +0000 (16:03 -0500)
 - 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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13502
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/bindings/python/bt2/bt2/event.py
src/bindings/python/bt2/bt2/event_class.py
src/bindings/python/bt2/bt2/stream.py
src/bindings/python/bt2/bt2/stream_class.py

index d430179cd217a641c6898f2f5a6daa4b2afd7f09..3a8e82c5017e520483f471972af03f5852091c3b 100644 (file)
@@ -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
index e0a8c70423d07fd1ac2ee4381c6b84a33fa955e5..100d6a7a1ec755392fa8ee03978d78dffdb501a2 100644 (file)
@@ -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]:
index 70eb5b0afcb22009d51422fa48d3fc6ee8d48933..71dafcd53c56ee8a6188906be6fdaffc9a52fea3 100644 (file)
@@ -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":
index 725b893d4d35772792fd14124620d9a4e78b8c9b..77c4ae79a08578dadb09046ad098ed5a1ebd0f96 100644 (file)
@@ -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(
This page took 0.026479 seconds and 4 git commands to generate.