[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread David Mertz, Ph.D.
On Mon, Mar 14, 2022, 7:52 PM Steven D'Aprano > I got "No results matched your query" on the second URL, at which point I > didn't bother with the first. > Hmm... while I don't support the proposal, I saw results at both links. Those links were the first good faith comments I saw from OP. A

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Mike Miller
On 2022-03-09 19:42, wfdc via Python-ideas wrote: Add a "replace" method to tuples that returnsa new tuple with the element at a given index replaced with a given value. Hmm, no one appears to have mentioned DateTime.replace(). Did I miss it?

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Steven D'Aprano
On Tue, Mar 15, 2022 at 10:51:21AM +1100, Steven D'Aprano wrote: > I got "No results matched your query" on the second URL, at which point > I didn't bother with the first. I tried again, with both URLs, and got plenty of hits this time. Perhaps I had a copy-paste error with the URLs, or a

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
> I got "No results matched your query" on the second URL, at which point I > didn't bother with the first. Check again in case it's an error.

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Steven D'Aprano
On Mon, Mar 14, 2022 at 11:53:37AM -0700, Christopher Barker wrote: > 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. How do we make a new list with a

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Steven D'Aprano
On Mon, Mar 14, 2022 at 04:38:48PM +, wfdc wrote: > > I would think that at least is obvious: the top voted Python > > question on StackOverflow currently has 11891 votes. This is two > > orders of magnitude less. > > Like I said, this puts it in the top 3031 / 1908740 = 0.00159 = 0.159%

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
Again, you neglected to answer the question: > what are the field names supposed to be if the datastructure is being treated > as a sequence, of possibly arbitrary length? > Since a namedtuple is supposed to be both a sequence and a record, the names > are part of the record interface, and

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Chris Angelico
On Tue, 15 Mar 2022 at 10:02, wfdc via Python-ideas wrote: > > See my previous response to Chris: > > > What are the named fields supposed to be if the datastructure is being > > treated as a sequence? Indices again? Then what's the point of using > > namedtuple rather than tuple in the first

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
> the OP has only had arguments like "namedtuples aren't sequences", which are > not what I'd call compelling. Why don't you answer the question I asked you? --- Original Message --- On Monday, March 14th, 2022 at 4:12 PM, Chris Angelico wrote: > On Tue, 15 Mar 2022 at 05:37,

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
See my previous response to Chris: > What are the named fields supposed to be if the datastructure is being > treated as a sequence? Indices again? Then what's the point of using > namedtuple rather than tuple in the first place? > And, by the way, field names must be valid identifiers. > So

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Oscar Benjamin
On Mon, 14 Mar 2022 at 22:21, Greg Ewing wrote: > > On 15/03/22 6:14 am, wfdc via Python-ideas wrote: > > The whole *point* is that namedtuples let you use *named fields* rather > > than indices. That's the point. That's the purpose. > > I would say the point of namedtuple is to let you use

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Greg Ewing
On 15/03/22 6:14 am, wfdc via Python-ideas wrote: The whole *point* is that namedtuples let you use *named fields* rather than indices. That's the point. That's the purpose. I would say the point of namedtuple is to let you use either field names or indices, whichever makes the most sense for

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Chris Angelico
On Tue, 15 Mar 2022 at 05:37, Christopher Barker wrote: > > > there has STILL been no answer to the questions of "why not >> >> use namedtuple" and "why not use a dataclass", > > > The OP may not have, but I at least answered why not namedtuple? very early > in the thread > > Chris A: sorry to

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Christopher Barker
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

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Christopher Barker
> there has STILL been no answer to the questions of "why not > use namedtuple" and "why not use a dataclass", The OP may not have, but I at least answered why not namedtuple? very early in the thread. the TL;DR: there are use cases for namedtuple, but if the only reason you would choose a

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
jax is another example that uses the name 'set' for this functionality: https://jax.readthedocs.io/en/latest/jax.numpy.html 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). Examples of this

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
And, by the way, field names must be valid identifiers. So again, what are the field names supposed to be if the datastructure is being treated as a sequence, of possibly arbitrary length? --- Original Message --- On Monday, March 14th, 2022 at 1:07 PM, Chris Angelico wrote: > On

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
The whole *point* is that namedtuples let you use *named fields* rather than indices. That's the point. That's the purpose. What are the named fields supposed to be if the datastructure is being treated as a sequence? Indices again? Then what's the point of using namedtuple rather than tuple

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Chris Angelico
On Tue, 15 Mar 2022 at 04:02, wfdc wrote: > > > A namedtuple IS a sequence. It is a tuple. They are deliberately designed > > to be drop-in replacements for tuples. > > I meant that they're not meant to be addressed as sequences. That's the whole > point of namedtuple: to avoid doing that. >

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
> A namedtuple IS a sequence. It is a tuple. They are deliberately designed to > be drop-in replacements for tuples. I meant that they're not meant to be addressed as sequences. That's the whole point of namedtuple: to avoid doing that. And the first point still applies. --- Original

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
> You're going to have to work harder than that to convince me. It's not clear > how many of those examples are unique, and most are concise and idiomatic. Ridiculous goalpost-moving. I literally just gave you 1000+ examples of this functionality being used, which is what you asked for,

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
> there has STILL been no answer to the questions of "why not use namedtuple" > and "why not use a dataclass" Christopher addressed that a long time ago. > no sample code provided See

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
See https://sourcegraph.com/search?q=context:global+lang:python+%5C%5B%5Cs*:%5Cs*%28i%7Cj%7Ck%7Cind%7Cindex%29%5Cs*%5C%5D%5Cs*%5C%2B%5Cs*%5C%28.*%5C%2C%5C%29%5Cs*%5C%2B%5Cs*%5B%5Cw%5C.%5D%2B%5C%5B%5Cs*%28i%7Cj%7Ck%7Cind%7Cindex%29%5Cs*%5C%2B%5Cs*1%5Cs*:%5Cs*%5C%5D=regexp

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
> wfdc (should we call you something which is not a random-looking string of > consonants?) wfdc is fine. > it might help if you could give examples of this functionality from other > languages or classes. What do they call the method? https://clojuredocs.org/clojure.core/assoc

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
> I would think that at least is obvious: the top voted Python question on > StackOverflow currently has 11891 votes. This is two orders of magnitude less. Like I said, this puts it in the top 3031 / 1908740 = 0.00159 = 0.159% of Python questions by vote count. That's not "a low number of

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Chris Angelico
On Tue, 15 Mar 2022 at 03:16, wfdc wrote: > > Yes, and dataclasses and namedtuples support this concept very nicely. You > > still haven't shown why neither works. > > 1. They're less efficient, as Christopher pointed out long ago. > > 2. They're not sequences, so conceptually the wrong tool for

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
You may not, but others do. See

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
See https://sourcegraph.com/search?q=context:global+lang:python+%5C%5B%5Cs*:%5Cs*%28i%7Cj%7Ck%7Cind%7Cindex%29%5Cs*%5C%5D%5Cs*%5C%2B%5Cs*%5C%28.*%5C%2C%5C%29%5Cs*%5C%2B%5Cs*%5B%5Cw%5C.%5D%2B%5C%5B%5Cs*%28i%7Cj%7Ck%7Cind%7Cindex%29%5Cs*%5C%2B%5Cs*1%5Cs*:%5Cs*%5C%5D=regexp and

[Python-ideas] Re: An unambiguous way of initializing an empty set and dictionary

2022-03-14 Thread Joao S. O. Bueno
Do you know what else would work for being able to enter empty sets? A prefix to {} , like "s" a = s{} and b = f{} for an empty frozenset (/me ducks, and hides in a place Chris won't find me) On Mon, Mar 14, 2022 at 10:29 AM Chris Angelico wrote: > On Tue, 15 Mar 2022 at 00:07, Joao S. O.

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Stephen J. Turnbull
Hi, You are clearly not making progress, and this list is no longer useful to you for this idea -- you know what you want, it's easy enough to implement, and you don't need our advice for that I assume. I suggest you give up on this list, write the code, make sure it's well-documented, and

[Python-ideas] Re: An unambiguous way of initializing an empty set and dictionary

2022-03-14 Thread Chris Angelico
On Tue, 15 Mar 2022 at 00:07, Joao S. O. Bueno wrote: > > > > On Mon, Mar 14, 2022 at 9:49 AM Chris Angelico wrote: >> >> On Mon, 14 Mar 2022 at 23:35, wrote: >> > >> > Currently: >> > l = [] # new empty list >> > t = () # new empty tuple >> > s = set() # new empty set (no clean and consistent

[Python-ideas] Re: An unambiguous way of initializing an empty set and dictionary

2022-03-14 Thread Joao S. O. Bueno
On Mon, Mar 14, 2022 at 9:49 AM Chris Angelico wrote: > On Mon, 14 Mar 2022 at 23:35, wrote: > > > > Currently: > > l = [] # new empty list > > t = () # new empty tuple > > s = set() # new empty set (no clean and consistent way of initializing > regarding the others) <<< > > d = {} # new empty

[Python-ideas] Re: An unambiguous way of initializing an empty set and dictionary

2022-03-14 Thread David Mertz, Ph.D.
On Mon, Mar 14, 2022 at 8:33 AM wrote: > Possible solution: > s = {} # new empty set > d = {:} # new empty dictionary (the ":" is a reference to key-value pairs) > I have suggested over the years—as have probably dozens of other people (maybe thousands)—that that would be a great spelling if

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Chris Angelico
On Mon, 14 Mar 2022 at 23:54, Christopher Barker wrote: > > Wow! > > Does anyone else see the irony in the fact that just a couple days ago, Chris > A lamented that Python-ideas seemed to > Immediately reject any new idea out of hand? And yes, Chris, you have joined > in the piling on in this

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Rob Cliffe via Python-ideas
On 11/03/2022 02:19, wfdc wrote: > This could cause confusion because str.replace() has a completely different API. We're talking about tuples here, not strings. Yes, I know, and tuples and strings are different.  But *humans* can be confused by "replace" having a totally different API in

[Python-ideas] X-Post: Adopting the concept of "Teams" (from PEP 8015)

2022-03-14 Thread Pradyun Gedam
This is basically an email asking for inputs on https://discuss.python.org/t/14210. It's not clear to me whether the expectation is that people post in two places or just one; so I'm going to avoid duplicating the contents here. TLDR from that proposal: PEP 8015 had proposed an SC + Core

[Python-ideas] Re: [Python-Dev] An unambiguous way of initializing an empty dictionary and set

2022-03-14 Thread Ethan Furman
On 3/13/22 14:49, joao.p.f.batista...@gmail.com wrote: > Currently: > l = [] # new empty list > t = () # new empty tuple > s = set() # new empty set (no clean and consistent way of initializing regarding the others) <<< > d = {} # new empty dictionary > > Possible solution: > s = {} # new empty

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Christopher Barker
Wow! Does anyone else see the irony in the fact that just a couple days ago, Chris A lamented that Python-ideas seemed to Immediately reject any new idea out of hand? And yes, Chris, you have joined in the piling on in this case. I didn’t think it was that bad, but this thread has been pretty

[Python-ideas] Re: An unambiguous way of initializing an empty set and dictionary

2022-03-14 Thread Chris Angelico
On Mon, 14 Mar 2022 at 23:35, wrote: > > Currently: > l = [] # new empty list > t = () # new empty tuple > s = set() # new empty set (no clean and consistent way of initializing > regarding the others) <<< > d = {} # new empty dictionary > > Possible solution: > s = {} # new empty set > d = {:}

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
Just to add, the following Sourcegraph queries provide good evidence of widespread use of this functionality:

[Python-ideas] hashlib.sha256(file_obj)

2022-03-14 Thread Aur Saraf
Hi, TL;DR: you can read just the code snippets and the last paragraph. First of all, I'm assuming hashlib is used to calculate hashes of large files in production very very often, such that even small performance and usability improvements would make a huge difference. If you don't share this

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
See also the following Sourcegraph query for examples of use of the second approach:

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Rob Cliffe via Python-ideas
On 11/03/2022 19:30, wfdc wrote: > I could (I believe) write "count" as an (inefficient) 1-liner, but not "index". I suggest it's harder than you think. (Try it!) How much harder? Can you post your candidate? It was you that said it could be a 1-liner.  The burden of proof is on you, if

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
See https://sourcegraph.com/search?q=context:global+lang:python+%5C%5B%5Cs*:%5Cs*%28i%7Cj%7Ck%7Cind%7Cindex%29%5Cs*%5C%5D%5Cs*%5C%2B%5Cs*%5C%28.*%5C%2C%5C%29%5Cs*%5C%2B%5Cs*%5B%5Cw%5C.%5D%2B%5C%5B%5Cs*%28i%7Cj%7Ck%7Cind%7Cindex%29%5Cs*%5C%2B%5Cs*1%5Cs*:%5Cs*%5C%5D=regexp and

[Python-ideas] Re: hashlib.sha256(file_obj)

2022-03-14 Thread Aur Saraf
It was brought to my attention that there is an open ticket for this. Moving discussion there: https://bugs.python.org/issue45150 Aur On Sun, Mar 13, 2022 at 6:19 PM Aur Saraf wrote: > Hi, > > TL;DR: you can read just the code snippets and the last paragraph. > > First of all, I'm assuming

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
See the following Sourcegraph query for examples of use of this pattern:

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
Now read what you said earlier: > So it appears the "problem" this is intended to solve is "Python isn't > Haskell." > But Haskell exists, and this is a non-problem looking for a solution. A bizarre incongruence, right? --- Original Message --- On Friday, March 11th, 2022 at 6:26 PM,

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread flightapisseo
Travel Portal Development We have a devoted group of engineers bringing unparalleled experience and information to the table for the clients, a one of a kind travel gateway that will certainly speed up the brand or business. https://www.flightapis.com/travel-portal-development

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Rob Cliffe via Python-ideas
On 11/03/2022 21:33, wfdc wrote: How about something like def index(self, x):     return next(i for i, a in enumerate(self) if a == x) Including start and end: def index(self, x, start=0, end=-1):     return next(i for i, a in tuple(enumerate(self))[start:end] if a == x) No cigar.  If the

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Steven D'Aprano
On Fri, Mar 11, 2022 at 01:38:57AM +, Rob Cliffe via Python-ideas wrote: > This could cause confusion because str.replace() has a completely > different API. The old "painter.draw()" versus "gun_slinger.draw()" problem. It does exist, but it's not generally a *major* problem. > And

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread David Mertz, Ph.D.
On Fri, Mar 11, 2022, 6:19 PM wfdc wrote: > > Likewise this which you wrote in another post: "Do you see why it's > useful to have immutability?" > > That's not insulting at all. It's a perfectly valid question to address to > a post that seems to be contesting the purpose of immutable types in

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Brendan Barnwell
On 2022-03-11 12:03, wfdc via Python-ideas wrote: I've used Python for 23+ years now. I've had occasion where I'd use this methods maybe in the low-tens of times. I'd call the purpose rare at best. This comment is useless without a base rate. What's the base rate for comparable methods that

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Stephen J. Turnbull
Game theorist here. wfdc via Python-ideas writes: > Do you see why it's useful to have immutability? Sure, it's potentially hashable. But I can't recall ever finding that useful in working with matrix games (loosely speaking, I mean games with a finite set of players, each with a finite

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
> they may have to spend time patiently arguing for it, answering objections, > demonstrating use cases, covering corner cases, discussing > alternatives/variations etc. That's what I'm doing. A direct writing style does not mean "belligerent". > But it seems to me that something you can

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread wfdc via Python-ideas
Please. If we're now talking about specific exceptions, my replace isn't a one-liner either. I was clearly referring to actual functionality. If you want that specific exception, 2 lines are sufficient. --- Original Message --- On Friday, March 11th, 2022 at 4:45 PM, Rob Cliffe wrote:

[Python-ideas] An unambiguous way of initializing an empty set and dictionary

2022-03-14 Thread joao . p . f . batista . 97
Currently: l = [] # new empty list t = () # new empty tuple s = set() # new empty set (no clean and consistent way of initializing regarding the others) <<< d = {} # new empty dictionary Possible solution: s = {} # new empty set d = {:} # new empty dictionary (the ":" is a reference to key-value

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Steven D'Aprano
On Fri, Mar 11, 2022 at 07:12:49PM +, wfdc via Python-ideas wrote: > > one Stack Overflow question, with a low number of votes > > Mind explaining why you say 159 is a "low number of votes" for a > StackOverflow question on Python? I would think that at least is obvious: the top voted

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Chris Angelico
On Sat, 12 Mar 2022 at 07:38, wfdc wrote: > > > you haven't shown us what your use-case actually is > > Any use-case where you'd want to modify an entry of an immutable sequence. That doesn't answer the question any more than your original code does. You're still starting with the assumption

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Rob Cliffe via Python-ideas
This is a common scenario on python-list or python-ideas: Someone has an idea that they think is the greatest thing since sliced bread.  They propose it, and feel hurt / rejected when they get pushback instead of everyone jumping up and down and saying how brilliant it is. Sometimes they are

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Chris Angelico
On Sat, 12 Mar 2022 at 08:53, wfdc via Python-ideas wrote: > > So do you propose getting rid of the tuple type entirely or not? > > Do you see why it's useful to have immutability? > Immutability is extremely useful. I use tuples VERY frequently. But I don't then need to replace one element in