Skip to content

Commit 722339d

Browse files
authored
[lldb] Revert custom __str__ in SBStructuredDataExtensions.i (#156721)
`__str__` was implemented in #155061, however its behavior was limited to only a some kinds of `SBStructuredData`. That was a breaking change, and this change removes that implementation of `__str__`, relying on the existing behavior which calls `GetDescription`.
1 parent adc0a2c commit 722339d

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

lldb/bindings/interface/SBStructuredDataExtensions.i

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ STRING_EXTENSION_OUTSIDE(SBStructuredData)
5252
else:
5353
raise TypeError("cannot convert generic to bool")
5454

55-
def __str__(self):
56-
data_type = self.GetType()
57-
if data_type in (
58-
eStructuredDataTypeString,
59-
eStructuredDataTypeInteger,
60-
eStructuredDataTypeSignedInteger,
61-
eStructuredDataTypeFloat,
62-
):
63-
return str(self.dynamic)
64-
else:
65-
raise TypeError(f"cannot convert {self.type_name(data_type)} to string")
66-
6755
def __int__(self):
6856
data_type = self.GetType()
6957
if data_type in (

lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def structured_data_api_test(self):
4848
s.Clear()
4949
error = example.GetDescription(s)
5050
self.assertSuccess(error, "GetDescription works")
51+
# Ensure str() doesn't raise an exception.
52+
self.assertTrue(str(example))
5153
if not "key_float" in s.GetData():
5254
self.fail("FAILED: could not find key_float in description output")
5355

@@ -344,7 +346,7 @@ def array_struct_test(self, dict_struct):
344346
self.fail("wrong output: " + str(output))
345347

346348
def test_round_trip_scalars(self):
347-
for original in (0, 11, -1, 0.0, 4.5, -0.25, "", "dirk", True, False):
349+
for original in (0, 11, -1, 0.0, 4.5, -0.25, True, False):
348350
constructor = type(original)
349351
data = lldb.SBStructuredData()
350352
data.SetFromJSON(json.dumps(original))
@@ -357,13 +359,6 @@ def test_dynamic(self):
357359
data.SetFromJSON(json.dumps(original))
358360
self.assertEqual(data.dynamic, original)
359361

360-
def test_round_trip_string(self):
361-
# No 0.0, it inherently does not round trip.
362-
for original in (0, 11, -1, 4.5, -0.25, "", "dirk"):
363-
data = lldb.SBStructuredData()
364-
data.SetFromJSON(json.dumps(original))
365-
self.assertEqual(str(data), str(original))
366-
367362
def test_round_trip_int(self):
368363
for original in (0, 11, -1):
369364
data = lldb.SBStructuredData()

0 commit comments

Comments
 (0)