functions, list, default parameters

Robert Kern robert.kern at gmail.com
Thu Nov 4 12:43:34 EDT 2010


On 11/4/10 2:07 AM, Lawrence D'Oliveiro wrote:
> In message<mailman.504.1288718704.2218.python-list at python.org>, Robert Kern
> wrote:
>
>> On 11/2/10 2:12 AM, Lawrence D'Oliveiro wrote:
>>
>>> In message<mailman.475.1288670833.2218.python-list at python.org>, Robert
>>> Kern wrote:
>>>
>>>> "Immutable objects" are just those without an obvious API for modifying
>>>> them.
>>>
>>> They are ones with NO legal language constructs for modifying them. Hint:
>>> if a selector of some part of such an object were to occur on the LHS of
>>> an assignment, and that would raise an error, then the object is
>>> immutable. The interpreter already knows all this.
>>
>> Incorrect. RHS method calls can often modify objects.
>
> So bloody what?

So examining LHS "selectors" is not sufficient for determining immutability.

>> Show me the algorithm that the interpreter can use to determine whether or
>> not an object is mutable.
>
> Go look in the code for the one it already uses in places where immutable
> objects are currently required.

Like hashes for dictionary keys? The code just calls the __hash__ method and 
trusts that you designed the object correctly. It does not verify anything. 
Although, strictly speaking, it doesn't require immutability of keys.

This is actually another one of those places where the Python language 
developers defined a concept but did not equip the interpreter with a way to 
verify compliance with the concept. A proper hashable object has a __hash__ 
method and an __eq__ method defined such that if two objects compare equal, they 
also hash equal. But nothing in the interpreter ever tries to verify that this 
is true. Nor can it except by an impossible exhaustive search of all the 
possible objects.

Care to point me to specific place in the Python code you are talking about? Or 
even just a slightly more specific direction would suffice. I don't really know 
what you might be talking about.

>>>> With various trickeries, I can mutate any immutable object.
>>>
>>> None within the Python language itself. Which is what we’re talking about
>>> here: a language construct which is probably one of the top 3 sources of
>>> grief to Python newbies. And not-so-newbies.
>>
>> "import ctypes" is within the Python language.
>
> And in the old BASIC days, we had “PEEK” and “POKE”. So by your reasoning,
> that invalidated the language rules, too.

I'm not talking about BASIC at all. Nor am I talking about invalidation of 
language rules in either BASIC or Python. I am only talking about whether or not 
the Python interpreter is able to determine if an object is immutable or not.

But this really is a side point. I'm happy to drop it.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list