[Python-bugs-list] [ python-Bugs-593154 ] Can't assign to __name__ or __bases__ of new class

noreply@sourceforge.net noreply@sourceforge.net
Fri, 09 Aug 2002 13:21:35 -0700


Bugs item #593154, was opened at 2002-08-09 13:55
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=593154&group_id=5470

Category: Type/class unification
Group: Python 2.3
Status: Open
Resolution: None
Priority: 3
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Guido van Rossum (gvanrossum)
>Summary: Can't assign to __name__ or __bases__ of new class

Initial Comment:
While it's rarely useful, there *are* situations where
assigning to __name__ or __bases__ of a class might
make sense.  So maybe this should be allowed.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-08-09 16:21

Message:
Logged In: YES 
user_id=6380

I should've mentioned that this is only a problem for
new-style classes. To see the difference, try "class
lcl(object):" instead of "class lcl:" in your example.

But perhaps you should consider using a metaclass if you
really want the class objects to have different names.

----------------------------------------------------------------------

Comment By: Gregory Smith (gregsmith)
Date: 2002-08-09 16:16

Message:
Logged In: YES 
user_id=292741

e.g.
def mkclass(cname,something):
    class lcl:
        def __init__(self):
       ... yada...
        def f(self, parm = something):
         ... yada ...

   ... yada...
    lcl.__name__ = cname
    return lcl


My understanding is that this function returns a different
class object (each cut from the same cloth, as it were)
each time it is called, but they all have the same name
by default.
If you are doing this (which is a cool thing to be able to do)
it certainly makes sense to give each class a different
name.  I just tried this,  however, and it seems to work.
__name__ got changed, and instances have the new name
in their default repr(). 



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=593154&group_id=5470