Last active
August 29, 2015 14:07
-
-
Save johnpena/b7ab67303b06fb1fdadc to your computer and use it in GitHub Desktop.
__subclasses__ changes when new classes come into scope via an import
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
| # 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