mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-26 17:26:22 +02:00
reflection for checking methods
This commit is contained in:
parent
3078362710
commit
dd82962937
4 changed files with 27 additions and 2 deletions
20
metagpt/utils/reflection.py
Normal file
20
metagpt/utils/reflection.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
"""
|
||||
class tools, including method inspection, class attributes, inheritance relationships, etc.
|
||||
"""
|
||||
|
||||
|
||||
def check_methods(C, *methods):
|
||||
"""
|
||||
Check if the class has methods. borrow from _collections_abc.
|
||||
Useful when implementing implicit interfaces, such as defining an abstract class, isinstance can be used for determination without inheritance.
|
||||
"""
|
||||
mro = C.__mro__
|
||||
for method in methods:
|
||||
for B in mro:
|
||||
if method in B.__dict__:
|
||||
if B.__dict__[method] is None:
|
||||
return NotImplemented
|
||||
break
|
||||
else:
|
||||
return NotImplemented
|
||||
return True
|
||||
Loading…
Add table
Add a link
Reference in a new issue