-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lldb] Revert custom __str__ in SBStructuredDataExtensions.i #156721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Revert custom __str__ in SBStructuredDataExtensions.i #156721
Conversation
@llvm/pr-subscribers-lldb Author: Dave Lee (kastiglione) ChangesFull diff: https://github.com/llvm/llvm-project/pull/156721.diff 2 Files Affected:
diff --git a/lldb/bindings/interface/SBStructuredDataExtensions.i b/lldb/bindings/interface/SBStructuredDataExtensions.i
index 6c452a0da3852..9def366a4cf11 100644
--- a/lldb/bindings/interface/SBStructuredDataExtensions.i
+++ b/lldb/bindings/interface/SBStructuredDataExtensions.i
@@ -52,18 +52,6 @@ STRING_EXTENSION_OUTSIDE(SBStructuredData)
else:
raise TypeError("cannot convert generic to bool")
- def __str__(self):
- data_type = self.GetType()
- if data_type in (
- eStructuredDataTypeString,
- eStructuredDataTypeInteger,
- eStructuredDataTypeSignedInteger,
- eStructuredDataTypeFloat,
- ):
- return str(self.dynamic)
- else:
- raise TypeError(f"cannot convert {self.type_name(data_type)} to string")
-
def __int__(self):
data_type = self.GetType()
if data_type in (
diff --git a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
index 6c00588636516..275ac03a5a86d 100644
--- a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
+++ b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
@@ -48,6 +48,8 @@ def structured_data_api_test(self):
s.Clear()
error = example.GetDescription(s)
self.assertSuccess(error, "GetDescription works")
+ # Ensure str() doesn't raise an exception.
+ self.assertTrue(str(example))
if not "key_float" in s.GetData():
self.fail("FAILED: could not find key_float in description output")
@@ -344,7 +346,7 @@ def array_struct_test(self, dict_struct):
self.fail("wrong output: " + str(output))
def test_round_trip_scalars(self):
- for original in (0, 11, -1, 0.0, 4.5, -0.25, "", "dirk", True, False):
+ for original in (0, 11, -1, 0.0, 4.5, -0.25, True, False):
constructor = type(original)
data = lldb.SBStructuredData()
data.SetFromJSON(json.dumps(original))
@@ -357,13 +359,6 @@ def test_dynamic(self):
data.SetFromJSON(json.dumps(original))
self.assertEqual(data.dynamic, original)
- def test_round_trip_string(self):
- # No 0.0, it inherently does not round trip.
- for original in (0, 11, -1, 4.5, -0.25, "", "dirk"):
- data = lldb.SBStructuredData()
- data.SetFromJSON(json.dumps(original))
- self.assertEqual(str(data), str(original))
-
def test_round_trip_int(self):
for original in (0, 11, -1):
data = lldb.SBStructuredData()
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/163/builds/25825 Here is the relevant piece of the build log for the reference
|
Follow up to llvm#155061 and llvm#156721. After discussing with @medismailben, the ideal course of to have a `__str__`, however, instead of throwing an exception, the fallback behavior calls `__repr__` (`GetDescription`). The main value of this is that `str(string_data)` will produce the string itself, not a quoted string as returned by `__repr__`/`GetDescription`.
__str__
was implemented in #155061, however its behavior was limited to only a some kinds ofSBStructuredData
. That was a breaking change, and this change removes that implementation of__str__
, relying on the existing behavior which callsGetDescription
.