class.__name__

My (very) recent patch #635933 allows assignment to both __name__ and
__bases__ of new-style classes. Given that the code for __bases__ is
much more complicated, it's a little odd that __name__ is the one
still giving me headaches.

It's all to do with dots.

An extension type like (e.g.) time.struct_time is created with a
tp_name of 'time.struct_time' which the accessors for __module__ and
__name__ translate thusly:

>>> time.struct_time.__name__
'struct_time'
>>> time.struct_time.__module__
'time'

User defined new-style classes _seem_ to behave similary:

>>> class C(object):
... pass
...
>>> C.__name__
'C'
>>> C.__module__
'__main__'

but under the hood it's quite different: tp_name is just "C" and
'__module__' is a key in C.__dict__. This shows up when in:

>>> C.__name__ = 'C.D'
>>> C.__name__
'D'
>>> C.__module__
'C'

 

 

 

 

你可能感兴趣的:(class.__name__)