Skip to content

Support copy.replace() on AST nodes #121141

Closed
@JelleZijlstra

Description

@JelleZijlstra

Feature or enhancement

Proposal:

I want this to work:

>>> n=ast.Name(id="x")
>>> copy.replace(n, id="y")
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    copy.replace(n, id="y")
    ~~~~~~~~~~~~^^^^^^^^^^^
  File "/Users/jelle/py/cpython/Lib/copy.py", line 293, in replace
    raise TypeError(f"replace() does not support {cls.__name__} objects")
TypeError: replace() does not support Name objects

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Labels

type-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions