python: move exception types out of __init__.py
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 19 Jun 2023 18:47:15 +0000 (14:47 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 21 Sep 2023 17:29:44 +0000 (13:29 -0400)
Move exception types defined in __init__.py.

 - Move _MemoryError to error.py
 - Move _IncompleteUserClass to component.py
 - Move the others to utils.py

I initially moved them to a new exceptions.py file, but I think that
it's just fine to move them in the existing files.  But it's a
possibility too, if y'all prefer that.

The goal of this commit is to make it easier to use these types
internally, using the form:

    from bt2 import utils as bt2_utils

    ... use bt2_utils.TryAgain ...

... in order to get rid of the internal `import bt2` imports.

Note that it would be possible to keep the exception types in
__init__.py and do:

    from bt2 import TryAgain

... and then use `TryAgain` in the code, but I think we prefer using a
module qualifier for whatever is imported.

Change-Id: I7d8dbdc28a3a2e3e38093903d622487a45fe7637
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10387
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/bindings/python/bt2/bt2/__init__.py
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/error.py
src/bindings/python/bt2/bt2/utils.py

index 38bb9b17dad280e7ead2a481ff204ae0a9dd6f02..cf4d9bd26603000c80557e234fd6789f8129d61e 100644 (file)
@@ -8,6 +8,7 @@ import sys
 from bt2.clock_class import ClockClassOffset
 from bt2.clock_snapshot import _ClockSnapshotConst
 from bt2.clock_snapshot import _UnknownClockSnapshot
+from bt2.component import _IncompleteUserClass
 from bt2.component import _SourceComponentClassConst
 from bt2.component import _FilterComponentClassConst
 from bt2.component import _SinkComponentClassConst
@@ -24,6 +25,7 @@ from bt2.error import _ComponentErrorCause
 from bt2.error import _ComponentClassErrorCause
 from bt2.error import _MessageIteratorErrorCause
 from bt2.error import _Error
+from bt2.error import _MemoryError
 from bt2.event_class import EventClassLogLevel
 from bt2.field import _BoolField
 from bt2.field import _BitArrayField
@@ -160,6 +162,10 @@ from bt2.query_executor import QueryExecutor
 from bt2.trace_collection_message_iterator import AutoSourceComponentSpec
 from bt2.trace_collection_message_iterator import ComponentSpec
 from bt2.trace_collection_message_iterator import TraceCollectionMessageIterator
+from bt2.utils import UnknownObject
+from bt2.utils import _OverflowError
+from bt2.utils import TryAgain
+from bt2.utils import Stop
 from bt2.value import create_value
 from bt2.value import BoolValue
 from bt2.value import _IntegerValue
@@ -227,35 +233,6 @@ if (sys.version_info.major, sys.version_info.minor) != (3, 4):
 del sys
 
 
-class _MemoryError(_Error):
-    """Raised when an operation fails due to memory issues."""
-
-
-class UnknownObject(Exception):
-    """
-    Raised when a component class handles a query for an object it doesn't
-    know about.
-    """
-
-    pass
-
-
-class _OverflowError(_Error, OverflowError):
-    pass
-
-
-class TryAgain(Exception):
-    pass
-
-
-class Stop(StopIteration):
-    pass
-
-
-class _IncompleteUserClass(Exception):
-    pass
-
-
 def _init_and_register_exit():
     from bt2 import native_bt
     import atexit
index 7f907cc9beee92e1f7e9ce96a3ec5805d994eccd..9deb5721955428a23b15fa096b7813479242c3c5 100644 (file)
@@ -16,6 +16,10 @@ import sys
 import bt2
 
 
+class _IncompleteUserClass(Exception):
+    pass
+
+
 # This class wraps a component class pointer. This component class could
 # have been created by Python code, but since we only have the pointer,
 # we can only wrap it in a generic way and lose the original Python
index e07a3f9002d1cb8c9a5fc32660c70e294e3d51ae..40f281d9e05a9b9c6ea64b3a5b57c4d1cae30401 100644 (file)
@@ -219,3 +219,7 @@ class _Error(Exception, abc.Sequence):
 
     def __str__(self):
         return self._str
+
+
+class _MemoryError(_Error):
+    """Raised when an operation fails due to memory issues."""
index 393f7ed883ec94f651355b7250d02601b190ff1f..849c7a3c2af099b78a5ab516038528ef54c39d01 100644 (file)
@@ -5,6 +5,28 @@
 import bt2
 from bt2 import logging as bt2_logging
 from bt2 import native_bt
+from bt2 import error as bt2_error
+
+
+class UnknownObject(Exception):
+    """
+    Raised when a component class handles a query for an object it doesn't
+    know about.
+    """
+
+    pass
+
+
+class _OverflowError(bt2_error._Error, OverflowError):
+    pass
+
+
+class TryAgain(Exception):
+    pass
+
+
+class Stop(StopIteration):
+    pass
 
 
 def _check_bool(o):
This page took 0.02724 seconds and 4 git commands to generate.