isinstance not working
Hi All, I am developing a custom user folder (based off of AccessControl.UserFolder code, and SimpleUserFolder), which inherits from BasicUser. There are two types of users in this folder, one is the AccessControl.User, and the other is a subclass of it. Inside getUserNames, I am trying to use isinstance, but it isn't working. It returns:
TypeError: isinstance() arg 2 must be a class or type
Here's the code that I'm using: class PortalUser(User): __doc__ = """This is the class for PortalUsers""" class PortalUserFolder(BasicUserFolder): ... ... """Return a sorted list of usernames""" def getUserNames(self,luser=1,puser=1): names = self.local_data.keys() names.sort() if (luser==1 and puser!=1): for name in names[:]: if (isinstance(name,PortalUser)): names.remove(name) elif (luser!=1 and puser==1): for name in names[:]: if not (isinstance(name,PortalUser): names.remove(name) return names Any ideas as to what's going on here, or why this is not working would be great! Oh, I've also tries using PortalUserFolder, and User as arg2 to isinstance. Thanks! Andy
Andrew Altepeter wrote at 2003-1-24 13:38 -0600:
I am developing a custom user folder (based off of AccessControl.UserFolder code, and SimpleUserFolder), which inherits from BasicUser.
There are two types of users in this folder, one is the AccessControl.User, and the other is a subclass of it.
Inside getUserNames, I am trying to use isinstance, but it isn't working. It returns:
TypeError: isinstance() arg 2 must be a class or type The idiom for using "isinstance" for an "ExtensionClass" looks like:
try: isAnInstance= isinstance(object,ExtClass) except TypeError: isAnInstance= 0 # now "isAnInstance" is true when "object" is an instance of "ExtClass" Dieter
participants (2)
-
Andrew Altepeter -
Dieter Maurer