[Python-Dev] assigning to new-style-class.name (original) (raw)
Michael Hudson mwh@python.net
26 Nov 2002 15:06:38 +0000
- Previous message: [Python-Dev] Talking Turkey
- Next message: [Python-Dev] assigning to new-style-class.__name__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.structtime.name 'struct_time' time.structtime.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'
which isn't really what I would have expected.
What I'd like to do is treat heap types and not-heap types distinctly:
For non-heap types, do as we do today: everything in tp_name up to the first dot is module, the rest is name. You can't change anything here, no worries about that.
For heap types, module is always dict['module'], name is always tp_name (or rather ((etype*)type)->name).
Comments? I think this is fine, so long as there aren't heap types that are created by some wierd means that leaves them without "'modules' in t.dict".
(If someone does
del t.dict['modules']
they deserve to lose, but we shouldn't crash. I don't expect this to be a problem).
Cheers, M.
-- First time I've gotten a programming job that required a drug test. I was worried they were going to say "you don't have enough LSD in your system to do Unix programming". -- Paul Tomblin -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html
- Previous message: [Python-Dev] Talking Turkey
- Next message: [Python-Dev] assigning to new-style-class.__name__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]