> Those links were the first good faith comments I saw from OP.
What do you mean by that, exactly?
> looking through those examples in a cursory manner made me think about 75% of
> the time "why are they doing this silly approach?"
Give several examples.
--- Original Message ---
On Mon
> 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.
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
, March 14th, 2022 at 7:04 PM, Chris Angelico wrote:
> On Tue, 15 Mar 2022 at 10:02, wfdc via Python-ideas
>
> python-ideas@python.org wrote:
>
> > See my previous response to Chris:
> >
> > > What are the named fields supposed to be if the datastructure is being
> 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, Christop
dentifiers.
> 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 6:19 PM, Greg Ewing
wrote:
> On 15/03/22 6:14 am, wfdc via Python-id
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 function
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 Tue,
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 in
> 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 Messa
>
> up the merge request) ping python-dev directly for a decision. If
>
> you're worried about coding style or exactly how the submission process
>
> works, core-mentors...@python.org will give you help on that with a
>
> minimum of backseat driving.
>
> wfdc via
> 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
https://sourcegraph.com/search?q=context:global+lang:python+%5C%5B%5Cs*:%5Cs*%28i%7Cj%7Ck%7Cind%7Cindex%29%5Cs
at 8:39 AM, Brendan Barnwell
wrote:
> 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 ca
> 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
https://immuta
them.
--- Original Message ---
On Monday, March 14th, 2022 at 8:32 AM, Steven D'Aprano
wrote:
> 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 explain
On Monday, March 14th, 2022 at 8:31 AM, Chris Angelico wrote:
> On Sat, 12 Mar 2022 at 08:53, wfdc via Python-ideas
>
> python-ideas@python.org wrote:
>
> > So do you propose getting rid of the tuple type entirely or not?
> >
> > Do you see why it's usefu
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&patternType=regexp
and
https://
t effectively re-implemented Christopher Barker's solution (which
>>>>> was also present in the StackOverflow thread), with the downside that it
>>>>> fails the immutability criterion.
>>>>>
>>>>> Saying "just be careful not to mutate
See also the following Sourcegraph query for examples of use of the second
approach:
https://sourcegraph.com/search?q=context:global+lang:python+%3D%5Cs*list%5C%28%5B%5Cw%5C.%5D%2B%5C%29%5Cs*%5Cw%2B%5C%5B%5Cw%2B%5C%5D%5Cs*%3D%5Cs*%5B%5Cw%5C.%5D%2B%5Cs*%5B%5Cw%5C.%5D%2B%5Cs*%3D%5Cs*tuple%5C%28%5Cw
2022 at 1:55 AM, Stephen J. Turnbull
wrote:
> 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 work
See the following Sourcegraph query for examples of use of this pattern:
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%2
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, D
stackoverflow.com/questions/2166147/namedtuple-replace-doesnt-work-as-described-in-the-documentation
> :
>>>> from collections import namedtuple
>>>> Point = namedtuple('Point', 'x,y')
>>>>
>>>> p = Point(x=11, y=22)
>>>&
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:
: To enforce
>>> immutability. Otherwise, why aren't you proposing getting rid of the tuple
>>> type entirely?
>>>
>>> --- Original Message ---
>>> On Friday, March 11th, 2022 at 4:29 PM, David Mertz, Ph.D.
>>> wrote:
>&g
mutable types: To enforce immutability.
> Otherwise, why aren't you proposing getting rid of the tuple type entirely?
>
> --- Original Message ---
> On Friday, March 11th, 2022 at 4:29 PM, David Mertz, Ph.D.
> wrote:
>
>> On Fri, Mar 11, 2022, 4:16 PM wfdc via Pytho
ave immutable types: To enforce
>> immutability. Otherwise, why aren't you proposing getting rid of the tuple
>> type entirely?
>>
>> --- Original Message ---
>> On Friday, March 11th, 2022 at 4:29 PM, David Mertz, Ph.D.
>> wrote:
>>
>>> O
olution. There's a reason we have immutable types: To enforce immutability.
Otherwise, why aren't you proposing getting rid of the tuple type entirely?
--- Original Message ---
On Friday, March 11th, 2022 at 4:29 PM, David Mertz, Ph.D.
wrote:
> On Fri, Mar 11, 2022, 4
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)
--- Original Message ---
On Friday, March 11th, 2022 at
> why haven't you used a list
1. A list is not immutable.
2. I don't want to modify the original sequence.
--- Original Message ---
On Friday, March 11th, 2022 at 4:07 PM, Marco Sulla
wrote:
> On Fri, 11 Mar 2022 at 21:39, wfdc via Python-ideas
>
> python-
> 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.
Modifying an immutable datastructure is not a contradictory statement. In fact,
there's a whole literature on it. See
https://en.wikipedia.org/wiki/Purely_functional_d
> the "not every one-line function needs to be a builtin" principle applies
> here, in my view.
The "not every one-line function needs to *not* be a builtin" principle cancels
it out.
And the "frequently-used functionality should be built-in" (Python's "batteries
included" philosophy) override
> 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 *are* part of the standard library, like index a
nal Message ---
On Friday, March 11th, 2022 at 2:36 PM, Chris Angelico wrote:
> On Sat, 12 Mar 2022 at 06:33, wfdc via Python-ideas
>
> python-ideas@python.org wrote:
>
> > > But humans can be confused by "replace" having a totally different API in
> &g
> would be in my top five considerations.
>
> But if you want it, subclassing is a thing.
>
> On Fri, Mar 11, 2022, 2:14 PM wfdc via Python-ideas
> wrote:
>
>>> one Stack Overflow question, with a low number of votes
>>
>> Mind explaining why you say 159 i
On Thursday, March 10th, 2022 at 8:38 PM, Rob Cliffe via Python-ideas
>> [](mailto:python-ideas@python.org) wrote:
>>
>>> This could cause confusion because str.replace() has a completely different
>>> API.
>>> And indeed if a replace method were added to t
way.
See namedtuple's ._replace method. namedtuples are also immutable. We simply
want the same functionality for tuple.
--- Original Message ---
On Friday, March 11th, 2022 at 4:41 AM, Paul Moore wrote:
> On Fri, 11 Mar 2022 at 02:20, wfdc via Python-ideas
>
> python-idea
> On the other hand, it might be an indication that a tuple is the wrong tool
> for the job.
1. It's not. The original tuple is not being mutated. And it may be desirable
to enforce that immutability at the type level. Hence the choice of tuple
rather than, say, list.
2. The same "objection" w
ount=-1)
> Whereas your suggestion can be written as a simple 1-liner, as you
> demonstrate. So there is no strong need for a new method for it.
> Best wishes
> Rob Cliffe
>
> On 10/03/2022 03:42, wfdc via Python-ideas wrote:
>
>> Add a "replace" method
Add a "replace" method to tuples that returns a new tuple with the element at a
given index replaced with a given value. Example implementation:
def replace(self, index, value):
return self[:index] + (value,) + self[index + 1:]
See
https://stackoverflow.com/questions/11458239/how-to-change-valu
39 matches
Mail list logo