Tuples and immutability

Ned Batchelder ned at nedbatchelder.com
Sat Mar 1 12:56:24 EST 2014


On 3/1/14 12:50 AM, Mark H. Harris wrote:
> On Friday, February 28, 2014 11:34:56 PM UTC-6, Ian wrote:
>
>> One very common example of tuples containing lists is when lists are
>> passed to any function that accepts *args, because the extra arguments
>> are passed in a tuple.  A similarly common example is when returning
>> multiple objects from a function, and one of them happens to be a
>> list, because again they are returned in a tuple.
>
>>      def f(*args):
>>          print(args)
>>          return (args[1:]
>>
>>      >>> result = f(1, 2, 3, [4, 5])
>>      (1, 2, 3, [4, 5])
>>      >>> print(result)
>>      (2, 3, [4, 5])
>
> I agree Ian... good points all.   ... again, I'm not arguing with anyone... just saying that an error (whatever we mean by that) should not half-way-fail....   we are only pointing out the problem... we have not idea what the solution is yet.
>
> Intuitively everyone can see that there is a problem here...  the debate cannot be answered either because of the inherent design of python (almost all of which we love). So, as they say, what is a mother to do?  ... I mean, some people's kids...
>
> I don't know how I propose to handle the problem... I think the first step is getting everyone to agree that there IS a problem... then debate how to tackle the solution proposals.
>
> marcus
>

Everyone can agree that it is not great to raise an exception and also 
leave the list modified.  But I very much doubt that anything will be 
done to change the situation.  All of the solutions are too extreme, and 
bring their own infelicities, and the actual problems caused by this 
scenario are vanishingly small.

BTW: I also am mystified why you uses ellipses to end your sentences, 
surely one period would be enough? :)

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list