I learned hard against using it. The problem is that the result depends on how the class definitions were imported:
- in the place where the object was created
- in the place where
isinstance check
If one import was relative and the other absolute, the check will fail. In essence, this will be similar to checking the equality of SomeClass and somepackage.SomeClass . It doesn’t even matter that they come from a single file and so on. In addition, there will be a similar result if somehow the root directory and somepackage directory are somepackage - then import in absolute style can indicate the path from any of the “source roots”, so as a result somepackage will somepackage two different imports in absolute style. in case of unsuccessful instance checks.
One can argue about how good practices will prevent this anyway, but good practices also basically come down to not taking risks. In this spirit, I prefer to put some kind of abstract method in a common class of ancestors, so that later I can rely on how things quack, and not how the interpreter considers them.
In Java, each class is converted to a fully qualified class name. They are unique within the program, and instance tests are very simple. In Python, they can be slippery.
source share