Skip to content

__replace__ on manually created AST objects has too many required arguments #133783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JelleZijlstra opened this issue May 9, 2025 · 1 comment
Labels
3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 9, 2025

Bug report

Bug description:

This should work but doesn't:

>>> fd=ast.FunctionDef(name="hi", args=[])
>>> fd
FunctionDef(name='hi', args=[], body=[], decorator_list=[], returns=None, type_comment=None, type_params=[])
>>> fd.__replace__()
Traceback (most recent call last):
  File "<python-input-16>", line 1, in <module>
    fd.__replace__()
    ~~~~~~~~~~~~~~^^
TypeError: FunctionDef.__replace__ missing 2 keyword arguments: 'returns', 'type_comment'.

cc @srittau

CPython versions tested on:

3.14

Operating systems tested on:

No response

Linked PRs

@picnixz
Copy link
Member

picnixz commented May 9, 2025

Considering I implemented copy.replace() for AST (in #121162), it might be my fault.

@picnixz picnixz added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.14 bugs and security fixes labels May 9, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 10, 2025
JelleZijlstra added a commit that referenced this issue May 10, 2025
GH-133797) (#133842)

gh-133783: Fix __replace__ on AST nodes for optional attributes (GH-133797)
(cherry picked from commit 7dddb4e)

Co-authored-by: Jelle Zijlstra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants