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>
from bt2.clock_class import ClockClassOffset
from bt2.clock_snapshot import _ClockSnapshotConst
from bt2.clock_snapshot import _UnknownClockSnapshot
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
from bt2.component import _SourceComponentClassConst
from bt2.component import _FilterComponentClassConst
from bt2.component import _SinkComponentClassConst
from bt2.error import _ComponentClassErrorCause
from bt2.error import _MessageIteratorErrorCause
from bt2.error import _Error
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
from bt2.event_class import EventClassLogLevel
from bt2.field import _BoolField
from bt2.field import _BitArrayField
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.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
from bt2.value import create_value
from bt2.value import BoolValue
from bt2.value import _IntegerValue
-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
def _init_and_register_exit():
from bt2 import native_bt
import atexit
+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
# 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
def __str__(self):
return self._str
def __str__(self):
return self._str
+
+
+class _MemoryError(_Error):
+ """Raised when an operation fails due to memory issues."""
import bt2
from bt2 import logging as bt2_logging
from bt2 import native_bt
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