Skip to content

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

Closed

Description

@JelleZijlstra

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

Activity

  1. added
    type-bug
    on May 9, 2025
  2. picnixz commented on May 9, 2025

    @picnixz
    Member

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

  3. added
    interpreter-core
    3.14
    on May 9, 2025
  4. added 2 commits that reference this issue on May 10, 2025
  5. added a commit that references this issue on May 10, 2025
  6. added a commit that references this issue on May 10, 2025
  7. added a commit that references this issue on Jul 12, 2025
  8. added a commit that references this issue on Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14interpreter-coretype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions