[Lldb-commits] [lldb] 7bf3cb3 - [lldb] Fix issue with re.Pattern availability
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 7 19:34:20 PST 2022
Author: Dave Lee
Date: 2022-11-07T19:33:57-08:00
New Revision: 7bf3cb3ee871b6707b7f5114a7fde61485df450e
URL: https://github.com/llvm/llvm-project/commit/7bf3cb3ee871b6707b7f5114a7fde61485df450e
DIFF: https://github.com/llvm/llvm-project/commit/7bf3cb3ee871b6707b7f5114a7fde61485df450e.diff
LOG: [lldb] Fix issue with re.Pattern availability
`re.Pattern` is introduced in Python 3.7. To support Python 3.6, fallback to typechecking against `SRE_Pattern`.
Differential Revision: https://reviews.llvm.org/D137582
Added:
Modified:
lldb/packages/Python/lldbsuite/test/decorators.py
lldb/packages/Python/lldbsuite/test/lldbtest.py
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py
index 3e3db099cd4a..dd47f6845ef2 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -80,7 +80,9 @@ def _match_decorator_property(expected, actual):
if isinstance(expected, no_match):
return not _match_decorator_property(expected.item, actual)
- if isinstance(expected, (re.Pattern, str)):
+ # Python 3.6 doesn't declare a `re.Pattern` type, get the dynamic type.
+ pattern_type = type(re.compile(''))
+ if isinstance(expected, (pattern_type, str)):
return re.search(expected, actual) is not None
if hasattr(expected, "__iter__"):
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 2d054f971cd0..63bad9d0241d 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -282,11 +282,14 @@ def check_value(self, test_base, val, error_msg=None):
test_base.assertSuccess(val.GetError())
+ # Python 3.6 doesn't declare a `re.Pattern` type, get the dynamic type.
+ pattern_type = type(re.compile(''))
+
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 @@ def check_value(self, test_base, val, error_msg=None):
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:
More information about the lldb-commits
mailing list