Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Frank-Rene Schäfer
(1) hash()-ability != immutability (!) Proof: class X: def __hash__(self): return 0 def pseudo_isimmutable(this): try: hash(this) return True except TypeError: return False shapeshifter = (1, 2, X()) print pseudo_isimmutable(shapeshifter)

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 8:12 PM, Frank-Rene Schäfer fsch...@gmail.com wrote: (1) hash()-ability != immutability (!) Proof: class X: def __hash__(self): return 0 x == y != y == x Proof: class X: def __eq__(self,other): return True class Y: def __eq__(self,other): return False

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Frank-Rene Schäfer
All you've done is proven that you can subvert things. By fiddling with __hash__, __eq__, and so on, you can make sets and dicts behave very oddly. Means nothing. To the contrary, it means everything about what 'isimmutable' could contribute: security against advert or inadvert insertion of

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 8:39 PM, Frank-Rene Schäfer fsch...@gmail.com wrote: All you've done is proven that you can subvert things. By fiddling with __hash__, __eq__, and so on, you can make sets and dicts behave very oddly. Means nothing. To the contrary, it means everything about what

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Frank-Rene Schäfer
So how do you figure out whether something's immutable or not? Are you going to ask the object itself? If so, stick with __hash__, and just follow the rule that mutable objects aren't hashable - which is, if I'm not mistaken, how things already are. And if not, then how? How will you know if

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Steven D'Aprano
On Tue, 12 Nov 2013 18:12:43 +1100, Chris Angelico wrote: def isimmutable(x): try: hash(x) return True except TypeError: return False I'm afraid that doesn't test for immutability. It tests for hashability, which is different. No well-behaved mutable

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Steven D'Aprano
On Tue, 12 Nov 2013 08:01:19 +0100, Frank-Rene Schäfer wrote: the existence of a built-in function 'isimmutable' puts the concept of immutability some more into the spotlight. That is an argument against the proposal, not in favour. The concept of immutability doesn't need to be in the

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Robert Kern
On 2013-11-12 11:14, Steven D'Aprano wrote: On Tue, 12 Nov 2013 18:12:43 +1100, Chris Angelico wrote: def isimmutable(x): try: hash(x) return True except TypeError: return False I'm afraid that doesn't test for immutability. It tests for hashability,

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Duncan Booth
=?UTF-8?Q?Frank=2DRene_Sch=C3=A4fer?= fsch...@gmail.com wrote: The ImmutableNester special class type would be a feature to help checks to avoid recursion. Objects of classes derived from ImmutableNester have no mutable access functions and allow insertion of members only at construction

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread random832
On Tue, Nov 12, 2013, at 4:39, Frank-Rene Schäfer wrote: All you've done is proven that you can subvert things. By fiddling with __hash__, __eq__, and so on, you can make sets and dicts behave very oddly. Means nothing. To the contrary, it means everything about what 'isimmutable' could

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Mark Lawrence
On 12/11/2013 11:10, Frank-Rene Schäfer wrote: Admittedly, I have no knowledge about the python implementation. There is no the regarding Python implementations. Cpython alone is at either 2.7.6 or 3.3.3 with 3.4 at alpha, then there's IronPython, Jython, PyPy and lots more that I'm sure

'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Frank-Rene Schäfer
I prepared a PEP and was wondering what your thoughts are about it: PEP:pep number Title: ``isimmutable(Obj)`` and/or ``ImmutableNester`` Version:version string Last-Modified: date string Author: Frank-Rene Schaefer, fsch...@users.sourceforge.net *

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Ned Batchelder
On Monday, November 11, 2013 3:47:45 PM UTC-5, Frank-Rene Schäfer wrote: I prepared a PEP and was wondering what your thoughts are about it: The best place to discuss proposals for changes to the Python language and library is the Python-Ideas mailing list:

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread random832
A built-in function 'isimmutable()' shall tell efficiently whether the object of concern is mutable or not. What's the benefit over attempting to hash() the object? copy.deepcopy already has special case for int, string, and tuples (including tuples that do and do not have mutable members) -

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Steven D'Aprano
On Mon, 11 Nov 2013 12:55:56 -0800, Ned Batchelder wrote: On Monday, November 11, 2013 3:47:45 PM UTC-5, Frank-Rene Schäfer wrote: I prepared a PEP and was wondering what your thoughts are about it: The best place to discuss proposals for changes to the Python language and library is the

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Mark Lawrence
On 12/11/2013 00:17, Steven D'Aprano wrote: On Mon, 11 Nov 2013 12:55:56 -0800, Ned Batchelder wrote: On Monday, November 11, 2013 3:47:45 PM UTC-5, Frank-Rene Schäfer wrote: I prepared a PEP and was wondering what your thoughts are about it: The best place to discuss proposals for changes

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 11:17 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 11 Nov 2013 12:55:56 -0800, Ned Batchelder wrote: On Monday, November 11, 2013 3:47:45 PM UTC-5, Frank-Rene Schäfer wrote: I prepared a PEP and was wondering what your thoughts are about it:

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Steven D'Aprano
Hi Frank-Rene, and welcome. Comments below. On Mon, 11 Nov 2013 21:47:45 +0100, Frank-Rene Schäfer wrote: I prepared a PEP and was wondering what your thoughts are about it: PEP:pep number Title: ``isimmutable(Obj)`` and/or ``ImmutableNester`` [...] *

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Frank-Rene Schäfer
A tuple is immutable but it may contain mutable objects. In larger hierarchies of objects it may become less obvious whether down the lines, there is some mutable object somewhere in the data tree. One can define a recursive function to check for immutability manually. However first, it may not

Re: 'isimmutable' and 'ImmutableNester'

2013-11-11 Thread Chris Angelico
On Tue, Nov 12, 2013 at 6:01 PM, Frank-Rene Schäfer fsch...@gmail.com wrote: A tuple is immutable but it may contain mutable objects. In larger hierarchies of objects it may become less obvious whether down the lines, there is some mutable object somewhere in the data tree. One can define a