types.AnyType - describing interfaces with sequences of types

Carlos Alberto Reis Ribeiro cribeiro at mail.inet.com.br
Wed Mar 28 08:42:51 EST 2001


At 02:56 28/03/01 -0800, you wrote:
>You get the idea. AnyType above will be eternally happy to be equivelent to
>anything you compare it to. Note that you can't do 'IntType is AnyType',
>that tells you actual object identity. Now, if you wanted it to only show up
>as 'equivelent' to TypeTypes, and not say, strings, (e.g. "string" ==
>AnyType) you could do a check to make sure what its being compared to is a
>TypeType.....

My first instinct it was to do something like this. However, it did not 
work, but because of a dumb mistake of mine :-) I tried again now, and this 
is the resulting code:

class CAnyType:
   def __cmp__(self, other):
         return (type(other) != TypeType)
   def __rcmp__(self, other):
         return (type(other) != TypeType)

AnyType = CAnyType()

That was my fault - I was trying to compare the class to IntType, but I 
need an instance for the code to work.

Anyway, I felt that should be a better way to make it, maybe be inheriting 
from some "UserType" object. However no such object exists. I don't know if 
"UserType" does not exist because it not make sense, or if it does not 
exist simply because no one else required it before. The way it is, it's 
inconsistent, because:

 >>> type(AnyType)        # should return "TypeType"
<type 'instance'>



Carlos Ribeiro






More information about the Python-list mailing list