Skip to content

Commit a7f1cb0

Browse files
committed
Fold in Ryan's magicsuper changes from its commit 7216702
- See rfk/magicsuper#6. - Also skip some tests for newsuper() on Py3
1 parent e580908 commit a7f1cb0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

future/builtins/newsuper.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,18 @@ def newsuper(typ=_SENTINEL, type_or_obj=_SENTINEL, framedepth=1):
7575
for typ in mro:
7676
# Find the class that owns the currently-executing method.
7777
for meth in typ.__dict__.values():
78-
if isinstance(meth, FunctionType):
79-
if meth.func_code is f.f_code:
80-
break # Aha! Found you.
81-
elif isinstance(meth, staticmethod):
82-
if meth.__func__.func_code is f.f_code:
83-
break # Aha! Found you.
78+
# Drill down through any wrappers to the underlying func.
79+
# This handles e.g. classmethod() and staticmethod().
80+
try:
81+
while not isinstance(meth,FunctionType):
82+
try:
83+
meth = meth.__func__
84+
except AttributeError:
85+
meth = meth.__get__(type_or_obj)
86+
except (AttributeError, TypeError):
87+
continue
88+
if meth.func_code is f.f_code:
89+
break # Aha! Found you.
8490
else:
8591
continue # Not found! Move onto the next class in MRO.
8692
break # Found! Break out of the search loop.

future/tests/test_magicsuper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import future.builtins.newsuper
99
from future.builtins import super
1010
from future.tests.base import unittest
11-
from future.utils import PY2
11+
from future import utils
1212

1313

1414
class TestMagicSuper(unittest.TestCase):
@@ -51,6 +51,7 @@ def other(self):
5151
ss = SubSub()
5252
self.assertEquals(ss.hello(),"hello world")
5353

54+
@unittest.skipIf(utils.PY3, "this test isn't relevant on Py3")
5455
def test_fails_for_oldstyle_class(self):
5556
class OldStyle:
5657
def testme(self):
@@ -72,7 +73,7 @@ def assertSuperEquals(self,sobj1,sobj2):
7273
assert sobj1.__thisclass__ is sobj2.__thisclass__
7374

7475
def test_call_with_args_does_nothing(self):
75-
if PY2:
76+
if utils.PY2:
7677
from __builtin__ import super as builtin_super
7778
else:
7879
from builtins import super as builtin_super
@@ -93,6 +94,7 @@ def calc(self,value):
9394
self.assertSuperEquals(builtin_super(cls), super(cls))
9495
self.assertSuperEquals(builtin_super(cls,obj), super(cls,obj))
9596

97+
@unittest.skipIf(utils.PY3, "this test isn't relevant for Py3's super()")
9698
def test_superm(self):
9799
class Base(object):
98100
def getit(self):

0 commit comments

Comments
 (0)