You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
json.load() can raise undocumented RecursionError #135835
>>> import json
>>> json.loads('['*9999)
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
json.loads('[' * 9999)
~~~~~~~~~~^^^^^^^^^^^^
File "/usr/lib/python3.13/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/usr/lib/python3.13/json/decoder.py", line 345, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/json/decoder.py", line 361, in raw_decode
obj, end = self.scan_once(s, idx)
~~~~~~~~~~~~~~^^^^^^^^
RecursionError: maximum recursion depth exceeded while decoding a JSON array from a unicode string
The same can be said for AttributeError that can be raised if you do json.load(1). Note that json.loads also doesn't say that it can raise an explicit TypeError if JSON object is incorrect.
Hiya. I wrote the comment that prompted this.
Five years ago, I raised this, and the team here decided it wasn't a flaw and closed it out - I'm surprised this has stayed open as long as it has.
That being said, both RecursionError and AttributeError appearing are probably surprising to the average Python programmer. They're leaks of implementation details. Not something I'd reasonably expect the average programmer to even realise is possible.
That surprise, is why I mentioned it on HN, and why someone else thought it worthy of "bug".
If something can always throw whatever, then we may as well get rid of classes for exceptions and catch everything.
But again... I've stated all this before. I expect this to simply close without changes.
I agree with @sobolevn. RecursionError, MemoryError and KeyboardInterrupt can be raised by almost anything. SystemExit or other exception can be added to this list if we add the default SIGTERM handler. That would be burdensome to add these exceptions to documentation of every function.
Activity
sobolevn commentedon Jun 23, 2025
Almost anything can raise
RecursionError. It is very similar toMemoryError. I am -1 on adding this to the docs.picnixz commentedon Jun 23, 2025
The same can be said for
AttributeErrorthat can be raised if you dojson.load(1). Note thatjson.loadsalso doesn't say that it can raise an explicit TypeError if JSON object is incorrect.LamentXU123 commentedon Jun 25, 2025
We usually only documented the relatively unique Errors IMO.
shakna-israel commentedon Jun 25, 2025
Hiya. I wrote the comment that prompted this.
Five years ago, I raised this, and the team here decided it wasn't a flaw and closed it out - I'm surprised this has stayed open as long as it has.
That being said, both RecursionError and AttributeError appearing are probably surprising to the average Python programmer. They're leaks of implementation details. Not something I'd reasonably expect the average programmer to even realise is possible.
That surprise, is why I mentioned it on HN, and why someone else thought it worthy of "bug".
If something can always throw whatever, then we may as well get rid of classes for exceptions and catch everything.
But again... I've stated all this before. I expect this to simply close without changes.
serhiy-storchaka commentedon Jun 26, 2025
I agree with @sobolevn.
RecursionError,MemoryErrorandKeyboardInterruptcan be raised by almost anything.SystemExitor other exception can be added to this list if we add the default SIGTERM handler. That would be burdensome to add these exceptions to documentation of every function.vstinner commentedon Jun 26, 2025
I close the issue.