From 4c4935bf825b84aeffa36234e95492fc6d2e9920 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 27 Aug 2019 00:57:30 -0400 Subject: [PATCH] python: fix all "do not use bare 'except'" warnings I wasn't sure why that mattered, but I found this explanation pretty good: https://help.semmle.com/wiki/pages/viewpage.action?pageId=29394005 In short, we don't want to catch KeyboardInterrupt and SystemExit. Change-Id: I0ee20f45ac715a0477c867960cfaea511518171f Signed-off-by: Simon Marchi Reported-by: flake8 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1980 Tested-by: jenkins --- src/bindings/python/bt2/bt2/component_descriptor.py | 6 +++--- src/bindings/python/bt2/bt2/field.py | 4 ++-- src/bindings/python/bt2/bt2/message_iterator.py | 2 +- src/bindings/python/bt2/bt2/value.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bindings/python/bt2/bt2/component_descriptor.py b/src/bindings/python/bt2/bt2/component_descriptor.py index 3134886b..bafba7e5 100644 --- a/src/bindings/python/bt2/bt2/component_descriptor.py +++ b/src/bindings/python/bt2/bt2/component_descriptor.py @@ -31,7 +31,7 @@ def _is_source_comp_cls(comp_cls): try: return issubclass(comp_cls, bt2_component._UserSourceComponent) - except: + except Exception: return False @@ -41,7 +41,7 @@ def _is_filter_comp_cls(comp_cls): try: return issubclass(comp_cls, bt2_component._UserFilterComponent) - except: + except Exception: return False @@ -51,7 +51,7 @@ def _is_sink_comp_cls(comp_cls): try: return issubclass(comp_cls, bt2_component._UserSinkComponent) - except: + except Exception: return False diff --git a/src/bindings/python/bt2/bt2/field.py b/src/bindings/python/bt2/bt2/field.py index ecbd9715..4d31f8fa 100644 --- a/src/bindings/python/bt2/bt2/field.py +++ b/src/bindings/python/bt2/bt2/field.py @@ -141,7 +141,7 @@ class _NumericField(_Field): def _spec_eq(self, other): try: return self._value == self._extract_value(other) - except: + except Exception: return False def __rmod__(self, other): @@ -393,7 +393,7 @@ class _StringField(_Field): def _spec_eq(self, other): try: return self._value == self._value_to_str(other) - except: + except Exception: return False def __lt__(self, other): diff --git a/src/bindings/python/bt2/bt2/message_iterator.py b/src/bindings/python/bt2/bt2/message_iterator.py index 5895b237..5ccec738 100644 --- a/src/bindings/python/bt2/bt2/message_iterator.py +++ b/src/bindings/python/bt2/bt2/message_iterator.py @@ -143,7 +143,7 @@ class _UserMessageIterator(_MessageIterator): msg = next(self) except StopIteration: raise bt2.Stop - except: + except Exception: raise utils._check_type(msg, bt2_message._Message) diff --git a/src/bindings/python/bt2/bt2/value.py b/src/bindings/python/bt2/bt2/value.py index 3acabe79..3001502a 100644 --- a/src/bindings/python/bt2/bt2/value.py +++ b/src/bindings/python/bt2/bt2/value.py @@ -132,7 +132,7 @@ class _NumericValue(_Value): def __eq__(self, other): try: return self._value == self._extract_value(other) - except: + except Exception: return False def __rmod__(self, other): @@ -383,7 +383,7 @@ class StringValue(collections.abc.Sequence, _Value): def __eq__(self, other): try: return self._value == self._value_to_str(other) - except: + except Exception: return False def __lt__(self, other): -- 2.34.1