[Python-ideas] pep-0484 - Forward references and Didactics - be orthogonal

Terry Reedy tjreedy at udel.edu
Wed Aug 26 07:50:35 CEST 2015


On 8/25/2015 1:48 PM, Sven R. Kunze wrote:

> I think the main issue here is the gab between intuition and what the
> compiler actually does. The following line:
>
> class MyClass: # first appearance of MyClass
>
> basically creates MyClass in the mind of the developer reading this
> piece of code.

I think the gap is less than you think ;-).  Or maybe we think 
differently when reading code.  Both human and compiler create the 
concept 'MyClass' (properly quoted) as an instance of the concept 'class'.

In a static language like C, types are only concepts in the minds of 
programmers and compilers.  There are no runtime char, int, float, or 
struct xyz objects, only the names or concepts.  When the compiler is 
done, there are only bytes in a sense not true of Python.

> Thus, he expects to be able to use it after this line.

One can use the string 'MyClass' in an annotation, for instance, and 
eventually dereference it to the object after the object is created.  A 
smart type checker could understand that 'MyClass' in annotations within 
the class MyClass statement means instances of the future MyClass object.

A developer should not expect to use not-yet-existent attributes and 
methods of the object.


-- 
Terry Jan Reedy



More information about the Python-ideas mailing list