[Python-bugs-list] [ python-Bugs-783528 ] Inconsistent results with super and __getattribute__

SourceForge.net noreply@sourceforge.net
Tue, 05 Aug 2003 07:19:15 -0700


Bugs item #783528, was opened at 2003-08-05 14:19
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=783528&group_id=5470

Category: Type/class unification
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Gonçalo Rodrigues (grodr)
Assigned to: Nobody/Anonymous (nobody)
Summary: Inconsistent results with super and __getattribute__

Initial Comment:
Consider the following scenario of property overriding:

>>> class Test(object):
... 	def __init__(self, n):
... 		self.__n = n
... 	#Properties.
... 	def __get_n(self):
... 		return self.__n
... 	def __set_n(self, n):
... 		self.__n = n
... 	n = property(__get_n, __set_n)
... 	
>>> a = Test(42)
>>> a.n
42
>>> a.n = 32
>>> a.n
32

Now, let us override the n property:

>>> class Test2(Test):
... 	def __init__(self, n):
... 		super(Test2, self).__init__(n)
... 	#Properties.
... 	def __get_n(self):
... 		return "got ya!"
... 	def __set_n(self, value):
... 		print "No way, jose!"
... 	n = property(__get_n, __set_n)
... 
>>> a = Test2(42)
>>> a.n
'got ya!'
>>> a.n = 0
No way, jose!
>>> a.n
'got ya!'
>>> super(Test2, a).n
42

So far so good, super is working well with properties. But 
now consider the following inconsistencies:

>>> super(Test2, a).__getattribute__('n')
'got ya!'
>>> super(Test2, a).n
42

Also:

>>> super(Test, Test2).__getattribute__('n')
<property object at 0x01103300>
>>> super(Test, Test2).__getattribute__('n').__get__(a)
'got ya!'
>>> super(Test, Test2).n
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'super' object has no attribute 'n'

The last one is particularly damaging, because:

>>> super(Test2, a).n = 32
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'super' object has no attribute 'n'

I think the above should work, but whatever’s the 
answer, together with the super(Test, Test2) odd 
results it does make impossible using super and setting 
properties together.

Tested with the latest Python 2.3 in win2k.

With my best regards,
G. Rodrigues

P.S: bug 729913 talks of similar issues at the end: super 
does not seem to intercept special methods.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=783528&group_id=5470