Skip to content

functools.cache vs sys.setrecursionlimit #127346

@gsbrodal

Description

@gsbrodal

Bug report

Bug description:

When running the below code with Python 3.13.0 on Windows

import functools
import sys

sys.setrecursionlimit(1_000_000)

@functools.cache
def double(n):
    return 2 + double(n - 1) if n > 0 else 0

print(f'{double(2_000) = }')

I get the following error

return 2 + double(n - 1) if n > 0 else 0
           ~~~~~~^^^^^^^
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded"

It appears that the sys.setrecursionlimit does not carry over to functools.cache. The error does not occur when using Python 3.12.3.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions