Classes and modules are singletons?

castironpi at gmail.com castironpi at gmail.com
Thu Mar 6 07:25:27 CET 2008


> I accept my question about classes being singletons is not well-formed,
> not even in my own mind. I guess one way of asking is, for any two class
> objects (not instances) C1 and C2, does "C1 == C2" imply "C1 is C2"?

C and D are instances of metaC in that.

class metaC( type ):
  def what( self ):
    return self

class C( metaclass= metaC ): pass
class D( metaclass= metaC ): pass

assert C is C.what() and D is D.what()
#print( C.what(), D.what() )

C= metaC('C',(),{})
D= metaC('D',(),{})
assert C is C.what() and D is D.what()
#print( C.what(), D.what() )

furthermore.



More information about the Python-list mailing list