Skip to content

Instantly share code, notes, and snippets.

@iamtonny
Created March 9, 2019 20:07
Show Gist options
  • Select an option

  • Save iamtonny/74be0009a3ca1574bc37b5f1641e27d7 to your computer and use it in GitHub Desktop.

Select an option

Save iamtonny/74be0009a3ca1574bc37b5f1641e27d7 to your computer and use it in GitHub Desktop.
How to find extension classes. Python
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