Re: Rationale for read-only property of co_code

2008-04-03 Thread Arnaud Delobelle
On Apr 3, 11:10 am, João Neves <[EMAIL PROTECTED]> wrote: > On Apr 3, 4:43 am, Scott David Daniels <[EMAIL PROTECTED]> wrote: > > > Nope:  If you change the code in-place, the whole stack's references > > to where they were running would need to get updated to corresponding > > locations in the new

Re: Rationale for read-only property of co_code

2008-04-03 Thread Peter Otten
João Neves wrote: > Let me give a very basic example. Say we have these two functions: I suppose you mean >>> def inc(x): return x + 1 ... >>> def dec(x): return x - 1 ... >>> inc(1), dec(1) (2, 0) > Examining the compiled bytecodes for these two functions: > > >>> inc.func_code.co_code > '|\

Re: Rationale for read-only property of co_code

2008-04-03 Thread João Neves
On Apr 3, 4:43 am, Scott David Daniels <[EMAIL PROTECTED]> wrote: > Nope: If you change the code in-place, the whole stack's references > to where they were running would need to get updated to corresponding > locations in the new code. _That_ is a lot of work. Ah, there it is. Now I get it, it

Re: Rationale for read-only property of co_code

2008-04-02 Thread John Nagle
Dan Upton wrote: >> The thing I've been wondering is why _is_ it read-only? In what >> circumstances having write access to co_code would break the language >> or do some other nasty stuff? >> >> João Neves > > I can't speak to Python's implementation in particular, but > self-modifying code i

Re: Rationale for read-only property of co_code

2008-04-02 Thread Scott David Daniels
João Neves wrote: > On 2 Abr, 21:38, "Chris Mellon" <[EMAIL PROTECTED]> wrote: >> On Wed, Apr 2, 2008 at 2:33 PM, João Neves <[EMAIL PROTECTED]> wrote: >>> On Apr 2, 5:41 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote: >>> > > The thing I've been wondering is why _is_ it read-only? In what >>> > > c

Re: Rationale for read-only property of co_code

2008-04-02 Thread Gabriel Genellina
En Wed, 02 Apr 2008 17:54:33 -0300, João Neves <[EMAIL PROTECTED]> escribió: > On 2 Abr, 21:38, "Chris Mellon" <[EMAIL PROTECTED]> wrote: >> There is no need to overwrite co_code. Create a new code object with >> your desired bytecode and use that instead. > > Yes, it may work (haven't tested -

Re: Rationale for read-only property of co_code

2008-04-02 Thread João Neves
On 2 Abr, 21:38, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On Wed, Apr 2, 2008 at 2:33 PM, João Neves <[EMAIL PROTECTED]> wrote: > > On Apr 2, 5:41 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote: > > > > The thing I've been wondering is why _is_ it read-only? In what > > > > circumstances having w

Re: Rationale for read-only property of co_code

2008-04-02 Thread Chris Mellon
On Wed, Apr 2, 2008 at 2:33 PM, João Neves <[EMAIL PROTECTED]> wrote: > On Apr 2, 5:41 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote: > > > The thing I've been wondering is why _is_ it read-only? In what > > > circumstances having write access to co_code would break the language > > > or do some

Re: Rationale for read-only property of co_code

2008-04-02 Thread João Neves
On Apr 2, 5:41 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote: > > The thing I've been wondering is why _is_ it read-only? In what > > circumstances having write access to co_code would break the language > > or do some other nasty stuff? > > > João Neves > > I can't speak to Python's implementation

Re: Rationale for read-only property of co_code

2008-04-02 Thread castironpi
On Apr 2, 11:41 am, "Dan Upton" <[EMAIL PROTECTED]> wrote: > >  The thing I've been wondering is why _is_ it read-only? In what > >  circumstances having write access to co_code would break the language > >  or do some other nasty stuff? > > >  João Neves > > I can't speak to Python's implementatio

Re: Rationale for read-only property of co_code

2008-04-02 Thread Dan Upton
> The thing I've been wondering is why _is_ it read-only? In what > circumstances having write access to co_code would break the language > or do some other nasty stuff? > > João Neves I can't speak to Python's implementation in particular, but self-modifying code in general is unpleasant. It

Re: Rationale for read-only property of co_code

2008-04-02 Thread Diez B. Roggisch
> I'm not quite sure I understood your question, sorry. And you won't. He's one of the resident trolls... Better killfile him ASAP :) Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: Rationale for read-only property of co_code

2008-04-02 Thread João Neves
On Apr 2, 4:35 pm, [EMAIL PROTECTED] wrote: > Are Python bytes codes Python byte codes? I'm not quite sure I understood your question, sorry. > Do you foresee any machine-dependent optimizations? In my personal case, I am not looking for optimizations in the generated bytecode. Let me give a ve

Re: Rationale for read-only property of co_code

2008-04-02 Thread castironpi
On Apr 2, 5:00 am, João Neves <[EMAIL PROTECTED]> wrote: > Hello all, > > I've got this question that has been nagging me for a few days now. > What are the reasons for us to have co_code as read-only? I've been > trying to get some info about it, but I kept hitting the wall. > > Correct me if I'm

Rationale for read-only property of co_code

2008-04-02 Thread João Neves
Hello all, I've got this question that has been nagging me for a few days now. What are the reasons for us to have co_code as read-only? I've been trying to get some info about it, but I kept hitting the wall. Correct me if I'm wrong, but as far as I understand, co_code represents the compiled by