Skip to content

Commit 5477db2

Browse files
meta.__abstractmethods__: better no dir(cls)
1 parent ce54ed2 commit 5477db2

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

modeled/meta.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
2323
.. moduleauthor:: Stefan Zimmermann <zimmermann.code@gmail.com>
2424
"""
25+
from itertools import chain
26+
2527
from moretools import cached, qualname, dictitems
2628

2729
from .base import metabase as base
@@ -160,8 +162,14 @@ def __abstractmethods__(cls):
160162
def abcnames():
161163
"""Generator.
162164
"""
163-
for name in dir(cls):
165+
# don't just iterate dir(cls) as it might contain dynamic members,
166+
# which maybe involve cls instantiation on getattr(),
167+
# which leads to endless recursion.
168+
# and anyway: abstractmethods should always be explicitly defined!
169+
for name in set(chain(dir(type(cls)),
170+
*(c.__dict__ for c in cls.mro())):
164171
if name == '__abstractmethods__':
172+
# another way to avoid recursion :)
165173
continue
166174
obj = getattr(cls, name, None)
167175
if obj is None:

0 commit comments

Comments
 (0)