Skip to content

Support copy.replace() on AST nodes #121141

Closed

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

Activity

  1. JelleZijlstra commented on Jun 28, 2024

    @JelleZijlstra
    MemberAuthor

    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.

  2. picnixz commented on Jun 28, 2024

    @picnixz
    Member

    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)

  3. JelleZijlstra commented on Jun 28, 2024

    @JelleZijlstra
    MemberAuthor

    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.

  4. picnixz commented on Jun 28, 2024

    @picnixz
    Member

    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).

  5. serhiy-storchaka commented on Jun 29, 2024

    @serhiy-storchaka
    Member

    I think that this would be useful.

  6. picnixz commented on Jun 29, 2024

    @picnixz
    Member

    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.

  7. added a commit that references this issue on Jul 4, 2024
  8. JelleZijlstra commented on Jul 4, 2024

    @JelleZijlstra
    MemberAuthor

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

    Thanks @picnixz!

  9. added a commit that references this issue on Jul 11, 2024
  10. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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