From 64e96b5d4769fa0d62afdcfb700cb24d779b74a3 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 24 Jul 2019 14:58:31 -0400 Subject: [PATCH] bt2: prepend `_` to names of exception classes the user cannot call `bt2._OverflowError` and `bt2._IncompleteUserClass` are classes the package's user cannot instantiate, so this patch adds the typical `_` prefix to indicate that. Signed-off-by: Philippe Proulx Change-Id: I42cb22311dac6d36dd7e57be86cc71d27ebab6a2 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1771 Tested-by: jenkins --- src/bindings/python/bt2/bt2/__init__.py.in | 4 ++-- src/bindings/python/bt2/bt2/component.py | 10 +++++----- src/bindings/python/bt2/bt2/utils.py | 4 ++-- tests/bindings/python/bt2/test_clock_class.py | 4 ++-- tests/bindings/python/bt2/test_component_class.py | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/bindings/python/bt2/bt2/__init__.py.in b/src/bindings/python/bt2/bt2/__init__.py.in index e4f01589..7859a22b 100644 --- a/src/bindings/python/bt2/bt2/__init__.py.in +++ b/src/bindings/python/bt2/bt2/__init__.py.in @@ -122,7 +122,7 @@ class InvalidObject(Exception): pass -class OverflowError(OverflowError): +class _OverflowError(OverflowError): pass @@ -134,7 +134,7 @@ class Stop(StopIteration): pass -class IncompleteUserClass(Exception): +class _IncompleteUserClass(Exception): pass diff --git a/src/bindings/python/bt2/bt2/component.py b/src/bindings/python/bt2/bt2/component.py index 7a79666a..efbfc343 100644 --- a/src/bindings/python/bt2/bt2/component.py +++ b/src/bindings/python/bt2/bt2/component.py @@ -483,7 +483,7 @@ class _UserComponentType(type): ) elif _UserSinkComponent in bases: if not hasattr(cls, '_consume'): - raise bt2.IncompleteUserClass( + raise bt2._IncompleteUserClass( "cannot create component class '{}': missing a _consume() method".format( class_name ) @@ -493,7 +493,7 @@ class _UserComponentType(type): cls, comp_cls_name, comp_cls_descr, comp_cls_help ) else: - raise bt2.IncompleteUserClass( + raise bt2._IncompleteUserClass( "cannot find a known component class base in the bases of '{}'".format( class_name ) @@ -530,21 +530,21 @@ class _UserComponentType(type): @staticmethod def _bt_set_iterator_class(cls, iter_cls): if iter_cls is None: - raise bt2.IncompleteUserClass( + raise bt2._IncompleteUserClass( "cannot create component class '{}': missing message iterator class".format( cls.__name__ ) ) if not issubclass(iter_cls, bt2.message_iterator._UserMessageIterator): - raise bt2.IncompleteUserClass( + raise bt2._IncompleteUserClass( "cannot create component class '{}': message iterator class does not inherit bt2._UserMessageIterator".format( cls.__name__ ) ) if not hasattr(iter_cls, '__next__'): - raise bt2.IncompleteUserClass( + raise bt2._IncompleteUserClass( "cannot create component class '{}': message iterator class is missing a __next__() method".format( cls.__name__ ) diff --git a/src/bindings/python/bt2/bt2/utils.py b/src/bindings/python/bt2/bt2/utils.py index 9c884175..3ad4f0b5 100644 --- a/src/bindings/python/bt2/bt2/utils.py +++ b/src/bindings/python/bt2/bt2/utils.py @@ -153,9 +153,9 @@ def _handle_func_status(status, msg=None): raise bt2.TryAgain(msg) elif status == native_bt.__BT_FUNC_STATUS_OVERFLOW_ERROR: if msg is None: - raise bt2.OverflowError + raise bt2._OverflowError else: - raise bt2.OverflowError(msg) + raise bt2._OverflowError(msg) elif status == native_bt.__BT_FUNC_STATUS_INVALID_OBJECT: if msg is None: raise bt2.InvalidObject diff --git a/tests/bindings/python/bt2/test_clock_class.py b/tests/bindings/python/bt2/test_clock_class.py index c8828ebf..d41b4671 100644 --- a/tests/bindings/python/bt2/test_clock_class.py +++ b/tests/bindings/python/bt2/test_clock_class.py @@ -181,7 +181,7 @@ class ClockClassTestCase(unittest.TestCase): return comp_self._create_clock_class(frequency=1000) cc = run_in_component_init(f) - with self.assertRaises(bt2.OverflowError): + with self.assertRaises(bt2._OverflowError): cc.cycles_to_ns_from_origin(2 ** 63) def test_create_uuid(self): @@ -278,7 +278,7 @@ class ClockSnapshotTestCase(unittest.TestCase): ) def test_ns_from_origin_overflow(self): - with self.assertRaises(bt2.OverflowError): + with self.assertRaises(bt2._OverflowError): self._msg_clock_overflow.default_clock_snapshot.ns_from_origin def test_eq_int(self): diff --git a/tests/bindings/python/bt2/test_component_class.py b/tests/bindings/python/bt2/test_component_class.py index 58e5a863..3e175c83 100644 --- a/tests/bindings/python/bt2/test_component_class.py +++ b/tests/bindings/python/bt2/test_component_class.py @@ -60,7 +60,7 @@ class UserComponentClassTestCase(unittest.TestCase): class MyIter(bt2._UserMessageIterator): pass - with self.assertRaises(bt2.IncompleteUserClass): + with self.assertRaises(bt2._IncompleteUserClass): class MySource(bt2._UserSourceComponent): pass @@ -69,7 +69,7 @@ class UserComponentClassTestCase(unittest.TestCase): class MyIter(bt2._UserMessageIterator): pass - with self.assertRaises(bt2.IncompleteUserClass): + with self.assertRaises(bt2._IncompleteUserClass): class MySource(bt2._UserSourceComponent, message_iterator_class=int): pass @@ -78,7 +78,7 @@ class UserComponentClassTestCase(unittest.TestCase): class MyIter(bt2._UserMessageIterator): pass - with self.assertRaises(bt2.IncompleteUserClass): + with self.assertRaises(bt2._IncompleteUserClass): class MyFilter(bt2._UserFilterComponent): pass @@ -87,7 +87,7 @@ class UserComponentClassTestCase(unittest.TestCase): class MyIter(bt2._UserMessageIterator): pass - with self.assertRaises(bt2.IncompleteUserClass): + with self.assertRaises(bt2._IncompleteUserClass): class MySink(bt2._UserSinkComponent): pass -- 2.34.1