[Python-ideas] namedtuple nit...
Antoine Rozo
antoine.rozo at gmail.com
Fri Jul 28 14:37:19 EDT 2017
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 "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute '__dict__'
>>> a.append(1)
>>> a.append(2)
>>> a
[1, 2]
2017-07-28 20:23 GMT+02:00 Mike Miller <python-ideas at mgmiller.net>:
> That's a subclass. Also:
>
> >>> class A(list): __slots__ = ()
> ...
> >>>
> >>> a = A()
> >>> a.foo = 'bar'
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> 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 does not accept attribute
>> assignment, is it not effectively immutable?
>>
>> No, not necessarily.
>>
>> class A(list): __slots__ = ()
>>
>> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Antoine Rozo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170728/685b41d9/attachment.html>
More information about the Python-ideas
mailing list