Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-12 Thread Christopher Barker
On Fri, Mar 8, 2019 at 1:52 AM Jonathan Fine wrote: > I've just learnt something new. Look at > > >>> from operator import iadd > >>> lst = [1, 2, 3] > >>> iadd(lst, 'hi') > [1, 2, 3, 'h', 'i'] > >>> lst > [1, 2, 3, 'h', 'i'] > > This shows that the proposals

Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-08 Thread Jonathan Fine
I've just learnt something new. Look at >>> from operator import iadd >>> lst = [1, 2, 3] >>> iadd(lst, 'hi') [1, 2, 3, 'h', 'i'] >>> lst [1, 2, 3, 'h', 'i'] This shows that the proposals dict.flow_update and dict.__iadd__ are basically the same. (I think this is quite

Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-06 Thread Christopher Barker
Do go read the recent thread about this - there is a lot there! Titled something like “fluent programming” Sorry — on a phone, kinda hard to check now. -CHB -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web

Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-06 Thread Brice Parent
Why not simply propose an external lib with FluentDict and other Fluent[Anything] already packaged? I don't know if I'd use it personnally, but it definitely could have some users. Le 05/03/2019 à 09:48, Jonathan Fine a écrit : SUMMARY Instead of using dict + dict, perhaps use

Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-05 Thread Wes Turner
dicttoolz has functions for working with these objects; including dicttoolz.merge (which returns a reference to the merged dicts but does not mutate the arguments passed). https://toolz.readthedocs.io/en/latest/api.html#dicttoolz

Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-05 Thread Greg Ewing
Christopher Barker wrote: That violates an important convention in Python: mutating methods do not return self. We really want to preserve that convention. Smalltalk has an abbreviated way of writing a series of method calls to the same object: x doThis; doThatWith: y; doTheOther. is

Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-05 Thread Jonathan Fine
I thank Guido and Christopher for their thoughtful comments. You certainly found some weak points. I chose the name 'flow' to match: https://en.wikipedia.org/wiki/Fluent_interface#Python Instead of my previous arg = defaults.copy().flow_update(options) one could instead from somewhere import

Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-05 Thread Christopher Barker
On Tue, Mar 5, 2019 at 12:53 AM Jonathan Fine wrote: > SUMMARY > Instead of using dict + dict, perhaps use dict.flow_update. Here, > flow_update is just like update, except that it returns self. That violates an important convention in Python: mutating methods do not return self. We really

Re: [Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-05 Thread Guido van Rossum
If you have to tell such a long and convoluted story to explain a name that you've picked out of the blue and that has no equivalent in other Python data types, it's probably a bad idea. If you're proposing that other mutating methods also gain a flow_XXX variant, please, no! That's like the

[Python-ideas] Suggestions: dict.flow_update and dict.__add__

2019-03-05 Thread Jonathan Fine
SUMMARY Instead of using dict + dict, perhaps use dict.flow_update. Here, flow_update is just like update, except that it returns self. BACKGROUND There's a difference between a sorted copy of a list, and sorting the list in place. >>> items = [2, 0, 1, 9] >>> sorted(items), items