Comparing two dynamically generated class types in python

This seems like another question , but in this case I would like to understand that type comparison between two types of classes is the same, but dynamically created.

Let's look at an example of this question overflowing https://stackoverflow.com/a/312960/212 :

class SecretBaseClass(object):
    pass

class Class(object):
    pass

ClassType1 = type(Class.__name__, (SecretBaseClass,), dict(Class.__dict__))
ClassType2 = type(Class.__name__, (SecretBaseClass,), dict(Class.__dict__))

If I then do:

print ClassType1 == ClassType2

my result is false.

I understand that I created two different types, but for a person they are the same. At what level does the comparison operator recognize the difference?

+4
source share
1 answer

__eq__, a == b id(a) == id(b), .. . ; type.

+6

Source: https://habr.com/ru/post/1536117/


All Articles