Fix previous commit for py2 and pypy.

This commit is contained in:
Valentin Lorentz 2019-02-07 21:35:39 +01:00
parent 969b9ed341
commit 233deee0d3
2 changed files with 12 additions and 4 deletions

View File

@ -159,7 +159,15 @@ def collect_extra_debug_data():
frame_locals = frame.f_locals frame_locals = frame.f_locals
for inspected in ('self', 'cls'): for inspected in ('self', 'cls'):
if inspected in frame_locals: if inspected in frame_locals:
for attr_name in dir(frame_locals[inspected]): try:
attribute_names = dir(frame_locals[inspected])
except Exception: # For Python 2 and Pypy
try:
attribute_names = list(
frame_locals[inspected].__dict__)
except Exception:
attribute_names = []
for attr_name in attribute_names:
try: try:
v = getattr(frame_locals[inspected], attr_name) v = getattr(frame_locals[inspected], attr_name)
except Exception: except Exception:

View File

@ -1179,9 +1179,9 @@ class UtilsPythonTest(SupyTestCase):
def test_dict(self): def test_dict(self):
class Foo: class Foo:
def __hasattr__(self, n): def __hasattr__(self, n):
raise Exception() raise Exception(n)
def __getattr__(self, n): def __getattr__(self, n):
raise Exception() raise Exception(n)
def f(): def f():
self = Foo() self = Foo()
@ -1199,7 +1199,7 @@ class UtilsPythonTest(SupyTestCase):
class Foo: class Foo:
__slots__ = ('bar',) __slots__ = ('bar',)
def __hasattr__(self, n): def __hasattr__(self, n):
raise Exception() raise Exception(n)
def __getattr__(self, n): def __getattr__(self, n):
raise Exception(n) raise Exception(n)