Fix inspection of classes with inheritance

This commit is contained in:
Christophe de Vienne 2011-10-21 18:51:32 +02:00
parent 974885de97
commit 259f94d8e8
2 changed files with 15 additions and 1 deletions

View File

@ -103,3 +103,13 @@ class TestTypes(unittest.TestCase):
assert hasattr(Inner, '_wsme_attributes') assert hasattr(Inner, '_wsme_attributes')
assert len(Inner._wsme_attributes) == 1 assert len(Inner._wsme_attributes) == 1
def test_inspect_with_inheritance(self):
class Parent(object):
parent_attribute = int
class Child(Parent):
child_attribute = int
types.register_type(Child)

View File

@ -93,7 +93,11 @@ def sort_attributes(class_, attributes):
names_order = [] names_order = []
try: try:
lines = [] lines = []
for line in inspect.getsourcelines(class_)[0]: for cls in inspect.getmro(class_):
if cls is object:
continue
lines[len(lines):] = inspect.getsourcelines(cls)[0]
for line in lines:
line = line.strip().replace(" ", "") line = line.strip().replace(" ", "")
if '=' in line: if '=' in line:
aname = line[:line.index('=')] aname = line[:line.index('=')]