kastiglione created this revision. kastiglione added reviewers: mib, rastogishubham, JDevlieghere. Herald added a project: All. kastiglione requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
`re.Pattern` is introduced in Python 3.7. To support Python 3.6, fallback to typechecking against `SRE_Pattern`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D137582 Files: lldb/packages/Python/lldbsuite/test/decorators.py lldb/packages/Python/lldbsuite/test/lldbtest.py Index: lldb/packages/Python/lldbsuite/test/lldbtest.py =================================================================== --- lldb/packages/Python/lldbsuite/test/lldbtest.py +++ lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -282,11 +282,14 @@ test_base.assertSuccess(val.GetError()) + # Python 3.6 doesn't have `re.Pattern`, fallback to `SRE_Pattern`. + pattern_type = getattr(re, 'Pattern', getattr(re, 'SRE_Pattern')) + if self.expect_name: test_base.assertEqual(self.expect_name, val.GetName(), this_error_msg) if self.expect_value: - if isinstance(self.expect_value, re.Pattern): + if isinstance(self.expect_value, pattern_type): test_base.assertRegex(val.GetValue(), self.expect_value, this_error_msg) else: @@ -296,7 +299,7 @@ test_base.assertEqual(self.expect_type, val.GetDisplayTypeName(), this_error_msg) if self.expect_summary: - if isinstance(self.expect_summary, re.Pattern): + if isinstance(self.expect_summary, pattern_type): test_base.assertRegex(val.GetSummary(), self.expect_summary, this_error_msg) else: Index: lldb/packages/Python/lldbsuite/test/decorators.py =================================================================== --- lldb/packages/Python/lldbsuite/test/decorators.py +++ lldb/packages/Python/lldbsuite/test/decorators.py @@ -80,7 +80,9 @@ if isinstance(expected, no_match): return not _match_decorator_property(expected.item, actual) - if isinstance(expected, (re.Pattern, str)): + # Python 3.6 doesn't have `re.Pattern`, fallback to `SRE_Pattern`. + pattern_type = getattr(re, 'Pattern', getattr(re, 'SRE_Pattern')) + if isinstance(expected, (pattern_type, str)): return re.search(expected, actual) is not None if hasattr(expected, "__iter__"):
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py =================================================================== --- lldb/packages/Python/lldbsuite/test/lldbtest.py +++ lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -282,11 +282,14 @@ test_base.assertSuccess(val.GetError()) + # Python 3.6 doesn't have `re.Pattern`, fallback to `SRE_Pattern`. + pattern_type = getattr(re, 'Pattern', getattr(re, 'SRE_Pattern')) + if self.expect_name: test_base.assertEqual(self.expect_name, val.GetName(), this_error_msg) if self.expect_value: - if isinstance(self.expect_value, re.Pattern): + if isinstance(self.expect_value, pattern_type): test_base.assertRegex(val.GetValue(), self.expect_value, this_error_msg) else: @@ -296,7 +299,7 @@ test_base.assertEqual(self.expect_type, val.GetDisplayTypeName(), this_error_msg) if self.expect_summary: - if isinstance(self.expect_summary, re.Pattern): + if isinstance(self.expect_summary, pattern_type): test_base.assertRegex(val.GetSummary(), self.expect_summary, this_error_msg) else: Index: lldb/packages/Python/lldbsuite/test/decorators.py =================================================================== --- lldb/packages/Python/lldbsuite/test/decorators.py +++ lldb/packages/Python/lldbsuite/test/decorators.py @@ -80,7 +80,9 @@ if isinstance(expected, no_match): return not _match_decorator_property(expected.item, actual) - if isinstance(expected, (re.Pattern, str)): + # Python 3.6 doesn't have `re.Pattern`, fallback to `SRE_Pattern`. + pattern_type = getattr(re, 'Pattern', getattr(re, 'SRE_Pattern')) + if isinstance(expected, (pattern_type, str)): return re.search(expected, actual) is not None if hasattr(expected, "__iter__"):
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits