diff --git a/Orange/widgets/data/owcreateclass.py b/Orange/widgets/data/owcreateclass.py index d85f6087f1..ffefb55805 100644 --- a/Orange/widgets/data/owcreateclass.py +++ b/Orange/widgets/data/owcreateclass.py @@ -250,7 +250,7 @@ class Warning(widget.OWWidget.Warning): class Error(widget.OWWidget.Error): class_name_duplicated = Msg("Class name duplicated.") class_name_empty = Msg("Class name should not be empty.") - invalid_regular_expression = Msg("Invalid regular expression.") + invalid_regular_expression = Msg("Invalid regular expression: {}") def __init__(self): super().__init__() @@ -458,15 +458,15 @@ def class_labels(self): return [label_edit.text() or f"C{next(class_count)}" for label_edit, _ in self.line_edits] - def check_patterns(self): + def invalid_patterns(self): if not self.regular_expressions: - return True - for pattern in self.active_rules: + return None + for _, pattern in self.active_rules: try: - re.compile(pattern[1]) + re.compile(pattern) except re.error: - return False - return True + return pattern + return None def update_counts(self): """Recompute and update the counts of matches.""" @@ -575,8 +575,8 @@ def _set_placeholders(): lab_edit.setPlaceholderText(label) _clear_labels() - if not self.check_patterns(): - self.Error.invalid_regular_expression() + if (invalid := self.invalid_patterns()) is not None: + self.Error.invalid_regular_expression(invalid) return self.Error.invalid_regular_expression.clear() @@ -594,8 +594,8 @@ def _set_placeholders(): def apply(self): """Output the transformed data.""" self.Error.clear() - if not self.check_patterns(): - self.Error.invalid_regular_expression() + if (invalid := self.invalid_patterns()) is not None: + self.Error.invalid_regular_expression(invalid) self.Outputs.data.send(None) return diff --git a/Orange/widgets/data/tests/test_owcreateclass.py b/Orange/widgets/data/tests/test_owcreateclass.py index c0796b0f3e..f265011820 100644 --- a/Orange/widgets/data/tests/test_owcreateclass.py +++ b/Orange/widgets/data/tests/test_owcreateclass.py @@ -387,10 +387,10 @@ def test_check_patterns(self): widget.line_edits[0][1].setText("[a") widget.regular_expressions = False - self.assertTrue(widget.check_patterns()) + self.assertIsNone(widget.invalid_patterns()) widget.regular_expressions = True - self.assertFalse(widget.check_patterns()) + self.assertEqual(widget.invalid_patterns(), "[a") def test_check_re_counts(self): widget = self.widget @@ -407,13 +407,14 @@ def test_check_re_counts(self): widget.apply() self.assertIsNotNone(self.get_output(self.widget.Outputs.data)) - widget.line_edits[0][1].setText("a[.*a") + widget.line_edits[1][1].setText("b[") self._check_counts([["", ""], ["", ""], ["", ""]]) self.assertTrue(widget.Error.invalid_regular_expression.is_shown()) + self.assertIn("b[", str(widget.Error.invalid_regular_expression)) widget.apply() self.assertIsNone(self.get_output(self.widget.Outputs.data)) - widget.line_edits[0][1].setText("a.*a") + widget.line_edits[1][1].setText("b") self._check_counts([["45", ""], ["30", "+ 4"], ["26", ""]]) self.assertFalse(widget.Error.invalid_regular_expression.is_shown()) widget.apply() diff --git a/i18n/si/msgs.jaml b/i18n/si/msgs.jaml index d5a895e0f5..301a197c8e 100644 --- a/i18n/si/msgs.jaml +++ b/i18n/si/msgs.jaml @@ -4741,7 +4741,7 @@ widgets/data/owcreateclass.py: class `Error`: Class name duplicated.: Spremenljivka s tem imenom že obstaja. Class name should not be empty.: Ime razreda ne more biti prazno. - Invalid regular expression.: Napačen regularni izraz. + 'Invalid regular expression: {}': 'Napačen regularni izraz: {}' def `__init__`: class_name: false New Class Name: Ime novega razreda