Message173217
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. |
|
Date |
User |
Action |
Args |
2012-10-17 23:43:06 | christopherthemagnificent | set | recipients:
+ christopherthemagnificent |
2012-10-17 23:43:06 | christopherthemagnificent | set | messageid: <1350517386.42.0.0716657058677.issue16271@psf.upfronthosting.co.za> |
2012-10-17 23:43:06 | christopherthemagnificent | link | issue16271 messages |
2012-10-17 23:43:06 | christopherthemagnificent | create | |
|