This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christopherthemagnificent
Recipients christopherthemagnificent
Date 2012-10-17.23:43:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1350517386.42.0.0716657058677.issue16271@psf.upfronthosting.co.za>
In-reply-to
Content
The output below is NOT typed at the Python interactive interpeter.  The ">>> " shows what is being evaluated and the line below it shows what the result it.

The output gets generated here:  (lines 418-449 of the attached file)

    def name_globalize_class(name, second=None):
        def decorator(cls):
            
            def printval(source, value=None):
                print(">>> " + source)
                if value is not None:
                    print(repr(value))
            print("in decorator: new name is:", repr(name))
            print()
            printval("cls", cls)
            printval("cls.__name__", cls.__name__)
            printval("cls.__qualname__", cls.__qualname__)
            printval('type.__dict__["__qualname__"].__get__(cls)',
                     type.__dict__["__qualname__"].__get__(cls))
            print()
            
            cls.__name__ = name
            cls.__qualname__ = name
            
            stuff = ">>> cls.__name__ = {0}\n>>> cls.__qualname__ = {0}\n"
            print(stuff.format(repr(name)))
            
            printval("cls.__name__", cls.__name__)
            printval("cls.__qualname__", cls.__qualname__)
            printval('type.__dict__["__qualname__"].__get__(cls)',
                     type.__dict__["__qualname__"].__get__(cls))
            printval("cls", cls)
            print()
            globals()[name] = cls
            pdb.set_trace()
            return cls
        return decorator
    
HERE IS THE OUTPUT:

>>> cls
<class '__main__._maketokensnodes.<locals>._TokenClass'>
>>> cls.__name__
'_TokenClass'
>>> cls.__qualname__
'_maketokensnodes.<locals>._TokenClass'
>>> type.__dict__["__qualname__"].__get__(cls)
'_maketokensnodes.<locals>._TokenClass'

>>> cls.__name__ = 'KEYWORD'
>>> cls.__qualname__ = 'KEYWORD'

>>> cls.__name__
'KEYWORD'
>>> cls.__qualname__
'KEYWORD'
>>> type.__dict__["__qualname__"].__get__(cls)
'_maketokensnodes.<locals>._TokenClass'
>>> cls
<class '__main__._maketokensnodes.<locals>._TokenClass'>

END OF OUTPUT

Note how after assigning to cls.__qualname__ it looks like the class's dictionary object has been assigned into, masking the class's C-level type attribute-level ht_qualname!

My gut feeling is that this has to be some kind of a bug.  Let me know if it is.
History
Date User Action Args
2012-10-17 23:43:06christopherthemagnificentsetrecipients: + christopherthemagnificent
2012-10-17 23:43:06christopherthemagnificentsetmessageid: <1350517386.42.0.0716657058677.issue16271@psf.upfronthosting.co.za>
2012-10-17 23:43:06christopherthemagnificentlinkissue16271 messages
2012-10-17 23:43:06christopherthemagnificentcreate