Skip to content

Instantly share code, notes, and snippets.

@johnpena
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save johnpena/b7ab67303b06fb1fdadc to your computer and use it in GitHub Desktop.

Select an option

Save johnpena/b7ab67303b06fb1fdadc to your computer and use it in GitHub Desktop.
__subclasses__ changes when new classes come into scope via an import
# crap/a.py
class A(object):
pass
print A.__subclasses__() # this will be an empty list, []
# crap/b.py
from a import A
class B(A):
pass
print A.__subclasses__() # this will now contain B, [<class '__main__.B'>]
# If another module imports a but not b, A.__subclasses__() will be an empty list, even if module b is in the path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment