8000 Merge pull request #107 from infoxchange/super-properties · thecodingchicken/python-future@a138a12 · GitHub
[go: up one dir, main page]

Skip to content

Commit a138a12

Browse files
committed
Merge pull request PythonCharmers#107 from infoxchange/super-properties
Do not attempt to run the properties code in super()
2 parents 132e6c5 + 780cd3d commit a138a12

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

future/builtins/newsuper.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
7979
# This handles e.g. classmethod() and staticmethod().
8080
try:
8181
while not isinstance(meth,FunctionType):
82-
try:
83-
meth = meth.__func__
84-
except AttributeError:
85-
meth = meth.__get__(type_or_obj)
82+
if isinstance(meth, property):
83+
# Calling __get__ on the property will invoke
84+
# user code which might throw exceptions or have
85+
# side effects
86+
meth = meth.fget
87+
else:
88+
try:
89+
meth = meth.__func__
90+
except AttributeError:
91+
meth = meth.__get__(type_or_obj)
8692
except (AttributeError, TypeError):
8793
continue
8894
if meth.func_code is f.f_code:

future/tests/test_super.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,26 @@ def g():
150150
c = f().__closure__[0]
151151
self.assertRaises(TypeError, X.meth, c)
152152

153+
def test_properties(self):
154+
class Harmless(object):
155+
bomb = ''
156+
157+
def walk(self):
158+
return self.bomb
159+
160+
class Dangerous(Harmless):
161+
@property
162+
def bomb(self):
163+
raise Exception("Kaboom")
164+
165+
def walk(self):
166+
return super().walk()
167+
168+
class Elite(Dangerous):
169+
bomb = 'Defused'
170+
171+
self.assertEqual(Elite().walk(), 'Defused')
172+
153173

154174
class TestSuperFromTestDescrDotPy(unittest.TestCase):
155175
"""

0 commit comments

Comments
 (0)
0