Skip to content

Support copy.replace() on AST nodes #121141

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 Jun 28, 2024 · 7 comments
Closed

Support copy.replace() on AST nodes #121141

JelleZijlstra opened this issue Jun 28, 2024 · 7 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Jun 28, 2024

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

@JelleZijlstra JelleZijlstra added the type-feature A feature request or enhancement label Jun 28, 2024
@JelleZijlstra JelleZijlstra self-assigned this Jun 28, 2024
@JelleZijlstra
Copy link
Member Author

I plan to work on this at some point, but if someone else is interested in it earlier, feel free to pick it up.

This could just possibly still go in 3.13, as copy.replace is new in 3.13.

@picnixz
Copy link
Member

picnixz commented Jun 28, 2024

I am interested in this one but not today (it's midnight now). However, when do you want this feature to be ready? (if you can give me an ETA, I can tell you if I have enough time)

@JelleZijlstra
Copy link
Member Author

I don't have a specific timeframe in mind except that I'd like it at least in 3.14, which gives us a little less than a year of leeway.

For 3.13, @Yhg1s (as release manager) and @serhiy-storchaka (as author of copy.replace) what do you think of adding this feature? It's late but it would be nice for copy.replace to be usable with more of the standard library.

@picnixz
Copy link
Member

picnixz commented Jun 28, 2024

which gives us a little less than a year of leeway.

I was more worried of whether you wanted it by the end of the week or the next week... One year or less if more than enough for me I think (if the feature is to be included).

@serhiy-storchaka
Copy link
Member

I think that this would be useful.

@picnixz
Copy link
Member

picnixz commented Jun 29, 2024

I'll work on that one after my thesis defense (next week). @JelleZijlstra would you like to assign the task to me please?

EDIT: Thank you Nikita!
EDIT 2: well I managed to do it today.

@JelleZijlstra
Copy link
Member Author

The implementation ended up pretty complicated, let's keep it for 3.14 only.

Thanks @picnixz!

noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants