[ python-Bugs-884064 ] metaclasses and __unicode__

SourceForge.net noreply at sourceforge.net
Sun Jan 25 05:24:41 EST 2004


Bugs item #884064, was opened at 2004-01-25 11:24
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=884064&group_id=5470

Category: Type/class unification
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Christoph Simon (arundo)
Assigned to: Nobody/Anonymous (nobody)
Summary: metaclasses and __unicode__

Initial Comment:
class Metaklasse (type) :
    def __str__ (cls) :
        return 'string'
    def __unicode__ (cls) :
        return u'unicode'
    def __int__ (cls) :
        return 7

class Klasse :
    __metaclass__ = Metaklasse
    def __str__ (cls) :
        return 'text'
    def __unicode__ (cls) :
        return u'unicodetext'
    def __int__ (cls) :
        return 9

print str(Klasse)
#print unicode(Klasse)
print int(Klasse)

print str(Klasse())
print unicode(Klasse())
print int(Klasse())

print unicode(Klasse)

The last print statemant raises an error

Traceback (most recent call last):
  File "Metaklasse.py", line 26, in -toplevel-
    print unicode(Klasse)
TypeError: unbound method __unicode__() must be called 
with Klasse instance as first argument (got nothing 
instead)

unicode() does not use the __unicode__ function of the 
metaclass. But int() and str() do.

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

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



More information about the Python-bugs-list mailing list