extend method of the list class could return a reference to the list so that we can chain method calls

*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* *(720) 653 -2408* *muldoonsamuel@gmail.com <muldoonsamuel@gmail.com>*

On 5/28/23 7:32 PM, Samuel Muldoon wrote:
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. -- Richard Damon

On Mon, May 29, 2023 at 2:52 AM Richard Damon <Richard@damon-family.org> wrote:
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

On 5/28/23 7:32 PM, Samuel Muldoon wrote:
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. -- Richard Damon

On Mon, May 29, 2023 at 2:52 AM Richard Damon <Richard@damon-family.org> wrote:
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
participants (3)
-
Richard Damon
-
Samuel Muldoon
-
Tal Einat