Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RecursionError during copy.deepcopy of an ast-tree with parent references #120108

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error
@15r10nk

Description

@15r10nk

Bug report

Bug description:

python 3.13 raises anRecursionError when I try todeepcopy the ast in the following example.

importastimportcopycode="""('',)while i < n:    if ch == '':        ch = format[i]        if ch == '':            if freplace is None:                '' % getattr(object)        elif ch == '':            if zreplace is None:                if hasattr:                    offset = object.utcoffset()                    if offset is not None:                        if offset.days < 0:                            offset = -offset                        h = divmod(timedelta(hours=0))                        if u:                            zreplace = '' % (sign,)                        elif s:                            zreplace = '' % (sign,)                        else:                            zreplace = '' % (sign,)        elif ch == '':            if Zreplace is None:                Zreplace = ''                if hasattr(object):                    s = object.tzname()                    if s is not None:                        Zreplace = s.replace('')            newformat.append(Zreplace)        else:            push('')    else:        push(ch)"""tree=ast.parse(code)# add a back reference to the parent nodefornodeinast.walk(tree):forchildinast.iter_child_nodes(node):child.parent=nodetree2=copy.deepcopy(tree)

output (Python 3.13.0b1+):

Traceback (mostrecentcalllast):File"/home/frank/projects/cpython/../cpython_bugs/deep_copy_ast_with_parents.py",line50,in<module>tree2=copy.deepcopy(tree)File"/home/frank/projects/cpython/Lib/copy.py",line162,indeepcopyy=_reconstruct(x,memo,*rv)File"/home/frank/projects/cpython/Lib/copy.py",line253,in_reconstructy=func(*args)File"/home/frank/projects/cpython/Lib/copy.py",line252,in<genexpr>args= (deepcopy(arg,memo)forarginargs)~~~~~~~~^^^^^^^^^^^File"/home/frank/projects/cpython/Lib/copy.py",line136,indeepcopyy=copier(x,memo)File"/home/frank/projects/cpython/Lib/copy.py",line196,in_deepcopy_listappend(deepcopy(a,memo))~~~~~~~~^^^^^^^^^...File"/home/frank/projects/cpython/Lib/copy.py",line162,indeepcopyy=_reconstruct(x,memo,*rv)File"/home/frank/projects/cpython/Lib/copy.py",line259,in_reconstructstate=deepcopy(state,memo)File"/home/frank/projects/cpython/Lib/copy.py",line136,indeepcopyy=copier(x,memo)File"/home/frank/projects/cpython/Lib/copy.py",line221,in_deepcopy_dicty[deepcopy(key,memo)]=deepcopy(value,memo)~~~~~~~~^^^^^^^^^^^^^File"/home/frank/projects/cpython/Lib/copy.py",line162,indeepcopyy=_reconstruct(x,memo,*rv)File"/home/frank/projects/cpython/Lib/copy.py",line253,in_reconstructy=func(*args)File"/home/frank/projects/cpython/Lib/copy.py",line252,in<genexpr>args= (deepcopy(arg,memo)forarginargs)~~~~~~~~^^^^^^^^^^^File"/home/frank/projects/cpython/Lib/copy.py",line136,indeepcopyy=copier(x,memo)RecursionError:maximumrecursiondepthexceeded

The problem can be reproduced on the current main (5c02ea8)

I was able to bisect the problem down toed4dfd8 (@JelleZijlstra may be you know more here)

The code in the example looks big but is already minimized.

I hope that this example is simple enough to find and fix the bug, I can try to find a smaller one if it is needed.

CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp