On Mon, Mar 14, 2022 at 11:16 AM wfdc via Python-ideas < python-ideas@python.org> wrote:
> jax is another example that uses the name 'set' for this functionality: > > https://jax.readthedocs.io/en/latest/jax.numpy.html set() strikes me as a better name for a mutating operation. Apparently Jax arrays are immutable, but from the Jax docs: "For example, instead of in-place array updates (x[i] = y), JAX provides an alternative pure indexed update function x.at[i].set(y)" I'd need to read more before I understood that that means (what does x.at[] return? But this does look pretty different than the proposal. Personally, I think the symmetry between this and datatime.replace and namedtuple._replace is actually a good thing, even though the API is a little different. On second thought, perhaps it wouldn't be a bad idea to extend this > proposal to built-in sequence types in general (list, str, tuple, and > bytes). > I don't think it should be added to mutable types -- there are already ways to do that, and there are any number of "make a new one with some change" methods that mutables don't have. Essentially, the API of mutable and immutable types is already different. Are you proposing that this be added to an ABC? That would be a heavier lift, and now that I think about it, there is no ABC for immutable sequences -- they are simply sequences -- which don't have any mutating methods. If you are proposing that it be added to a handful of built-in types -- I don't think that should be done for the sake of symmetry, but only if it's useful for that type. -- do we often want to replace the nth character in a string? or the nth byte in a bytes object? Maybe? I don't think I"ve ever needed to do that. > If extended beyond tuples, we would have to address the name collision > with the existing 'replace' methods of str and bytes. In that case, > something like 'set' or 'update' might work. (I prefer the former for its > conciseness.) > yup -- so I suppose another name would be helpful for future extending. (dict has update() -- would that add confusion?) -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YH6HN24IGK4I3C7D2L2ZIX7CDIOVERLU/ Code of Conduct: http://python.org/psf/codeofconduct/