Created
March 9, 2019 20:07
-
-
Save iamtonny/74be0009a3ca1574bc37b5f1641e27d7 to your computer and use it in GitHub Desktop.
How to find extension classes. Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import inspect | |
| class A: | |
| pass | |
| class B(A): | |
| pass | |
| def find_extentions(interface, module=__name__): | |
| module = sys.modules[module] | |
| clsmembers = inspect.getmembers(module, inspect.isclass) | |
| extentions = [] | |
| for clsmember_name, clsmember in clsmembers: | |
| if clsmember != interface and issubclass(clsmember, interface): | |
| extentions.append(clsmember) | |
| return extentions | |
| print(find_extentions(A)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment