Asserting object class

Adi adi at
Thu Jun 10 06:35:48 EDT 1999

Thank you, but:

Michael Hudson wrote:

> Adi <adi at> writes:
> > In a method, I'd like to assert that a parameter is an object which is
> > of a specific class or has this class as it's base class.
> I think that this will do what you want:
> def method(self,p):
>     assert isinstance(p,self.__class__)

Actually it does'nt. When this method is called, it is called on a subclass
of the superclass I wan't to assert the parameter is of.

So it fails. What I do now is:

class X:
    def m(self, p):
        assert isinstance(p, X)

> the following also does the same:
> def method(self,p):
>     assert issubclass(p.__class__,self.__class__)

I have'nt tested, but I suspect it will do the same.


i-data is a leading vendor of printing connectivity solutions,
e-forms software, and networking products.
More information is available at

Disclaimer: I speak for myself, not my employer.

More information about the Python-list mailing list