Re: [Python-ideas] namedtuple nit...

2017-07-29 Thread Chris Barker
On Sat, Jul 29, 2017 at 6:49 AM, Nick Coghlan wrote: > It's possible to write builtin types that are truly immutable, and > there are several examples of that (direct instances of object, tuple > instances, instances of the builtin numeric types), Maybe this is an argument for namedtuple to be

Re: [Python-ideas] namedtuple nit...

2017-07-29 Thread Nick Coghlan
On 29 July 2017 at 04:56, Mike Miller wrote: > Nice. Ok, so there are different dimensions of mutability. > > Still, haven't found any "backdoors" to object(), the one I claimed was > immutable. It's possible to write builtin types that are truly immutable, and there are several examples of that

Re: [Python-ideas] namedtuple nit...

2017-07-28 Thread Mike Miller
Nice. Ok, so there are different dimensions of mutability. Still, haven't found any "backdoors" to object(), the one I claimed was immutable. -Mike ___ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/python-

Re: [Python-ideas] namedtuple nit...

2017-07-28 Thread Antoine Rozo
Yes, but A objects have no slots, no dict, do not accept attribute assignment, but are mutable. >>> a = A() >>> a [] >>> a.__slots__ () >>> a.__dict__ Traceback (most recent call last): File "", line 1, in AttributeError: 'A' object has no attribute '__dict__' >>> a.append(1) >>> a.append(2) >>

Re: [Python-ideas] namedtuple nit...

2017-07-28 Thread Mike Miller
That's a subclass. Also: >>> class A(list): __slots__ = () ... >>> >>> a = A() >>> a.foo = 'bar' Traceback (most recent call last): File "", line 1, in AttributeError: 'A' object has no attribute 'foo' -Mike On 2017-07-28 01:06, Antoine Rozo wrote: > If an object has no slots or dict and

Re: [Python-ideas] namedtuple nit...

2017-07-28 Thread Antoine Rozo
> If an object has no slots or dict and does not accept attribute assignment, is it not effectively immutable? No, not necessarily. class A(list): __slots__ = () 2017-07-28 10:00 GMT+02:00 Mike Miller : > > > On 2017-07-27 18:02, Chris Angelico wrote: > > As Ivan said, this is to do with __slot

Re: [Python-ideas] namedtuple nit...

2017-07-28 Thread Mike Miller
On 2017-07-27 18:02, Chris Angelico wrote: > As Ivan said, this is to do with __slots__. It's nothing to do with > immutability: >>> object().__slots__ Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute '__slots__' >>> object().__dict__ T

Re: [Python-ideas] namedtuple nit...

2017-07-27 Thread Steven D'Aprano
On Thu, Jul 27, 2017 at 05:09:56PM -0700, Mike Miller wrote: > I've never liked that error message either: > > >>> object().foo = 'bar' > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'object' object has no attribute 'foo' > > > Should say the "obj

Re: [Python-ideas] namedtuple nit...

2017-07-27 Thread Chris Angelico
On Fri, Jul 28, 2017 at 10:09 AM, Mike Miller wrote: > I've never liked that error message either: > > >>> object().foo = 'bar' > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'object' object has no attribute 'foo' > > > Should say the "object is imm

Re: [Python-ideas] namedtuple nit...

2017-07-27 Thread Mike Miller
I've never liked that error message either: >>> object().foo = 'bar' Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 'foo' Should say the "object is immutable," not writable, or something of the sort. On 2017-07-27 09:

Re: [Python-ideas] namedtuple nit...

2017-07-27 Thread Ivan Levkivskyi
This error message is the same for types with __slots__, and probably it is indeed a bit too terse. -- Ivan On 27 July 2017 at 18:26, Chris Barker wrote: > Since we are talking about namedtuple and implementation, I just noticed: > > In [22]: Point = namedtuple('Point', ['x', 'y']) > In [23]:

[Python-ideas] namedtuple nit...

2017-07-27 Thread Chris Barker
Since we are talking about namedtuple and implementation, I just noticed: In [22]: Point = namedtuple('Point', ['x', 'y']) In [23]: p = Point(2,3) In [24]: p.x = 5 --- AttributeErrorTraceback (most