[Python-ideas] Support other dict types for type.__dict__
rob.cliffe at btinternet.com
Tue Feb 28 00:18:57 CET 2012
On 27/02/2012 21:53, Oleg Broytman wrote:
> On Mon, Feb 27, 2012 at 07:55:50PM +0100, Victor Stinner wrote:
>> 2012/2/27 Oleg Broytman<phd at phdru.name>:
>>> On Mon, Feb 27, 2012 at 06:35:57PM +0000, Rob Cliffe wrote:
>>>> I suggested a "mutable" attribute some time ago.
>>>> This could lead to finally doing away with one of Python's FAQs: Why
>>>> does python have lists AND tuples? They could be unified into a
>>>> single type.
>>> The main difference between lists and tuples is not mutability but
>>> usage: lists are for a (unknown) number of similar items (a list of
>>> messages, e.g.), tuples are for a (known) number of different items at
>>> fixed positions (an address is a tuple of (country, city, street
>>> address), for example).
>> And tuple doesn't have append, extend, remove, ... methods.
> Tuples are *also* read only, but being read only lists is not their
> main purpose.
With respect, I think you are thinking too narrowly, conditioned by
Items of a list do not have to be similar (there is nothing in the
language that implies that).
And tuples are often - conceptually - extended, even though it actually
has to be done by building a new tuple - Python even allows you to write
tuple1 += tuple2
A unified type would have "mutating" methods such as append - it's just
that they would raise an error if the object's flag (however it was
implemented) defined it as immutable.
I visualised an actual object attribute, e.g. __mutable__, that could be
set to a boolean value. But having __mutable__() and __immutable__()
methods as suggested by Eric is an alternative. And there may well be
More information about the Python-ideas