Observations on the three pillars of Python execution

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Aug 5 13:29:13 EDT 2011


Eric Snow wrote:

> On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> Eric Snow wrote:
>>
>>> In Python, three types of objects have special syntax and mechanics
>>> for their instantiation, during which a code object is generated:
>>> modules, classes, and functions.
>>
>> I believe you are labouring under a misapprehension. Modules and classes
>> don't generate code objects.
> 
> Sorry for any confusion.  I was talking specifically about the their
> instantiation through their respective special syntax.  During that
> process a code object is generated for each.


Do you believe that this process of generating a code object and throwing it
away is a part of the Python language specification, which any compiler
must do in order to call itself "Python", or a mere implementation detail?

Is this documented somewhere? If it is not documented, what makes you think
that it happens at all? You are writing as if it were self-evidently true,
but I don't believe it is self-evident at all. I think you need to
demonstrate the truth of two of those three pillars, not just take them for
granted.


> For classes and modules 
> the code object is executed and then discarded.  I covered this
> explicitly in one of the observations.

I think your definition of "explicitly" and mine differ here.


> Agreed that [non-builtin] functions are the only objects that have a
> code object attribute.  However, they are not the only objects for
> which a code object is generated and executed.

Are you talking about the fact that importing a module, class statements and
function statements all involve executing a block of code?

How does that differ from executing any other fragment of code?

Modules are special, of course, because they can get compiled to byte-code,
but I trust you're not talking about .pyc files. 



-- 
Steven




More information about the Python-list mailing list