Skip to content

Commit 099fc4f

Browse files
gh-143544: Adjust regression test to allow SystemError
1 parent ed2c55c commit 099fc4f

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

Lib/test/test_json/test_fail.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,30 +237,28 @@ def test_linecol(self):
237237
(line, col, idx))
238238

239239
def test_reentrant_jsondecodeerror_does_not_crash(self):
240+
# gh-143544
240241
import json
241242

242243
orig_json_error = json.JSONDecodeError
243244
orig_decoder_error = json.decoder.JSONDecodeError
244245

245246
class Trigger:
246247
def __call__(self, *args):
247-
import json as mod
248248
# Remove JSONDecodeError during construction to trigger re-entrancy
249-
if hasattr(mod, "JSONDecodeError"):
250-
del mod.JSONDecodeError
251-
if hasattr(mod.decoder, "JSONDecodeError"):
252-
del mod.decoder.JSONDecodeError
249+
del json.JSONDecodeError
250+
del json.decoder.JSONDecodeError
253251
return ValueError("boom")
254252

255253
hook = Trigger()
256254
try:
257255
json.JSONDecodeError = hook
258256
json.decoder.JSONDecodeError = hook
259257

260-
# The exact exception type is not important here; the test
261-
# only verifies that we do not crash or trigger a SystemError.
258+
# The exact exception type is not important here;
259+
# this test only ensures we don't crash.
262260
with self.assertRaises(Exception):
263-
self.loads('"\\uZZZZ"')
261+
json.loads('"\\uZZZZ"')
264262

265263
finally:
266264
json.JSONDecodeError = orig_json_error

Misc/NEWS.d/next/Library/2026-01-08-19-38-02.gh-issue-143544.4jRCBJ.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)