Subclassing built-in classes

MonkeeSage MonkeeSage at gmail.com
Fri Oct 6 13:28:49 EDT 2006



On Oct 6, 4:58 am, Maric Michaud <m... at aristote.info> wrote:
> As the first post said "...couldn't python (in theory)...", I was discussing
> if it would be possible for python (in some future version) to manage the
> literals so that they use the constructors in the __builtin__ module, I
> didn't say it works actually (I'm aware it's not the case).

Hi Maric,

I think the problem Steve was pointing out is this: how do you make a
literal use a constructor that is not available until *after* the
literal has been constructed? In other words, python currently does
this: 1) parses plaintext into bytecode (at which point literals are
constructed), 2) executes bytcode (at which point custom constructors
are available). The only way I can see to do what I asked is to, during
bytecode compilation, mark a literal in the AST as being a literal (+1
bits, at least, on every literal until it is constructed) but not
actually constructing it until the point of execution (+? time to go
back through the object space looking for marked objects and
constructing them). I don't know enough about python internals to know
if that would be a problem, but I seriously doubt it would be
implemented without some pressing use cases. So it is possible, but
probably not plausible.

Regards,
Jordan




More information about the Python-list mailing list