[Python-Dev] assigning to new-style-class.__name__

Guido van Rossum guido@python.org
Tue, 26 Nov 2002 11:43:33 -0500


> >>> C.__name__ = 'C.D'
> >>> C.__name__
> 'D'
> >>> C.__module__
> 'C'
> 
> which isn't really what I would have expected.

In fact, this makes the feature useless (its main use is to "fix" the
name of nested classes).

> What I'd like to do is treat heap types and not-heap types distinctly:
> 
> For non-heap types, do as we do today: everything in tp_name up to the
> first dot is __module__, the rest is __name__.  You can't change
> anything here, no worries about that.
> 
> For heap types, __module__ is always __dict__['__module__'], __name__
> is always tp_name (or rather ((etype*)type)->name).

+1

> Comments?  I think this is fine, so long as there aren't heap types
> that are created by some wierd means that leaves them without
> "'__modules__' in t.__dict__".
> 
> (If someone does
> 
> del t.__dict__['__modules__']
> 
> they deserve to lose, but we shouldn't crash.  I don't expect this to
> be a problem).

Correct.

--Guido van Rossum (home page: http://www.python.org/~guido/)