On Mon, May 29, 2023 at 2:52 AM Richard Damon <rich...@damon-family.org> wrote:
>
> On 5/28/23 7:32 PM, Samuel Muldoon wrote:
> > *Currently, list.extend does not allow method chaining.*
> > *
> > *
> > *parameters = [
> >     "zero or more",
> >     "zero or more".upper(),
> >     "zero or more".lower(),
> >     "Zero or More"
> > *
> > *].extend(["(0, +inf)", "[0; +in**f]"])*
> > *
> > *
> > *parameters.extend(["{0, \u221E}"]).append("(0 inf)")
> > *
> > *
> > *
> >
> > *Samuel Muldoon*
> >
> My understanding is that it is a deliberate choice that mutating member
> functions return NONE, rather than the object (to allow chaining)
> because otherwise it is too easy to think it return a new copy of the
> object (like operation that aren't mutations).
>
> Thinking you got a new copy when you are working with the original
> object gives hard to find problems.
>
> Since the operations return NONE, mistakenly trying to chain hits an
> obvious, and normally easy to fix error.
>
> It just says that "chaining" has become less pythonic.

Indeed, this was a deliberate choice, and I believe this will not be changed.

If you really want to use method-chaining style, there are libraries
on PyPI to facilitate that. Take a look at PyDash[1], or at my own
take on this, funcy-chain[2].

[1] pydash.readthedocs.io
[2] github.com/taleinat/funcy-chain

- Tal
_______________________________________________
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/F3LALA33SCESQJ2FGXMTOBQ5PJB6DGXV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to