You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement __replace__ method for CPython 3.13 #16887
Python 3.13 introduces a new copy.replace function in the copy standard library package that, effectively, does the same as e.g. .replicate() for Time: make a shallow copy that replaces some items (replicate is a bit more limited, though, in that it only allows replacing the format).
Describe the desired outcome
Support for copy.replace in as many astropy subpackages as makes sense.
Although this looks low priority, I think we could try to support this from the get go in our first release with Python 3.13 support (at least in our first non-bugfix one). A question is whether we should also deprecate custom methods at the same time (or at all). Deprecating on Python 3.12 or older wouldn't make much sense but we could have the warning show up only for Python >= 3.13
I think I answered my own question by reading the implementations more closely: replicate methods in general have a copy boolean flag, which doesn't match how copy.replace is supposed to behave, so I don't think we should deprecate anything at the moment.
I think a good candidate is astropy.cosmology._src.parameter.core.Parameter, which already has a clone method which is essentially an alternative for __replace__. We could easily move the logic to the standard method and deprecate the clone method.
I think a good candidate is astropy.cosmology._src.parameter.core.Parameter, which already has a clone method which is essentially an alternative for replace. We could easily move the logic to the standard method and deprecate the clone method.
Activity
neutrinoceros commentedon Aug 28, 2024
Although this looks low priority, I think we could try to support this from the get go in our first release with Python 3.13 support (at least in our first non-bugfix one). A question is whether we should also deprecate custom methods at the same time (or at all). Deprecating on Python 3.12 or older wouldn't make much sense but we could have the warning show up only for Python >= 3.13
neutrinoceros commentedon Aug 28, 2024
I think I answered my own question by reading the implementations more closely:
replicatemethods in general have acopyboolean flag, which doesn't match howcopy.replaceis supposed to behave, so I don't think we should deprecate anything at the moment.nstarman commentedon Dec 9, 2024
Almost exactly #15750 😆.
neutrinoceros commentedon Sep 21, 2026
I think a good candidate is
astropy.cosmology._src.parameter.core.Parameter, which already has aclonemethod which is essentially an alternative for__replace__. We could easily move the logic to the standard method and deprecate theclonemethod.nstarman commentedon Sep 22, 2026
Agreed!
Are you interested in opening a PR?
neutrinoceros commentedon Sep 22, 2026
Yes. Probably not this week though.
neutrinoceros commentedon Oct 2, 2026
note: I won't have time to dedicate to this in the forseeable future (end of 2026)
nstarman commentedon Oct 2, 2026
I'm gonna explore this