◐ Shell
clean mode source ↗

msgpack.fallback DEFAULT_RECURSE_LIMIT smaller than python 3.10 default

Hi there. I was running the pure python msgpack.fallback implementation against this sample.json test file in the tencent/rapidjson repo. Packing hit a ValueError: recursion limit exceeded.

It looks like this stems from the DEFAULT_RECURSE_LIMIT. Changing to use the sys.getrecursionlimit() resolves as it has a default of 1000 in 3.10. Looking at the pyproject.toml it seems like support is >= python 3.10 so I think it should be fine to update the constant, or drop it completely in favor of just inheriting the python stack limit. An advantage of doing that is the users ability to control it with sys.setrecursionlimit(). Also then a RecursionError can be raised instead of ValueError.

Simple reproduction:

from msgpack.fallback import Packer
import json

with open('sample.json') as f:
    Packer().pack(json.load(f))  # ValueError

This works fine, but the public Packer.pack api doesn't expose it directly:

from msgpack.fallback import Packer
import json
import sys

with open('sample.json') as f:
    Packer()._pack(json.load(f), nest_limit=sys.getrecursionlimit())  # 1000

Thanks!