[Python-3000] gettype

Jack Diederich jack at psynchronous.com
Wed Aug 2 05:14:37 CEST 2006

On Tue, Aug 01, 2006 at 07:29:51PM -0700, Talin wrote:
> tomer filiba wrote:
> > that's surly anachronism :)
> > 
> > o.__class__ is a little more typing and will surely scare newbies.
> > moreover, type(x) and x.__class__ can return different things
> > (you can fool __class__, but not type()).
> > 
> > for my part, i'm fine with any form that makes a distinction between
> > the metaclass "type" and the inquire-type "type".
> > call it o.__class__, gettype() or typeof(), just don't mix that with
> > the metaclass
>  From a code style perspective, I've always felt that the magical 
> __underscore__ names should not be referred to ouside of the class 
> implementing those names. The double underscores are an indication that 
> this method or property is in most normal use cases referred to 
> implicitly by use rather than explicitly by name; Thus str() invokes 
> __str__ and so on.

The paired double underscores indicate that the function is special to 
the instance's class.  C++ converts understand this just fine until you
mention that classes are themselves instances at which point the grey
matter takes a while to settle again [guilty].  After that reshuffling
you are again assaulted because the stack stops.  The class of a class
is a type but the class of a class of a class is still a type.  Turtles
all the way down.

See the recent thread on python-checkins for some discussion on why
"isinstance(ob, type(type))" isn't just legal -- it's backwards compatible!


More information about the Python-3000 mailing list