[Types-sig] Basic questions

Greg Stein gstein@lyra.org
Tue, 21 Dec 1999 12:37:48 -0800 (PST)

On Tue, 21 Dec 1999, skaller wrote:
> 	If I may: there is an issue here which
> some people may not have realised: recursive types.

These are not possible in Python because definitions are actually
constructed at runtime. The particular name/object must be available at
that point in the execution.

> In an interface file, this can be handled by 
> two passes.
> 	In implementation files, it is much
> harder, since scoping rules are dynamic.
> This is a good argument for interface files.
> Example:
> 	class X:
> 		def f(y:Y): ...

This fails. Y is not defined.

> 	class Y:
> 		def g(x:X): ...
> Resolving this in a single pass requires
> backpatching, which is messy: but using two
> passes leads to difficult ambiguities
> due to renaming:
> 	class X:
> 		def h(): ...
> Ok -- so now, which X does the X in g refer to?

Y.g referred to the X that existed at that point in time.

> In python, names are bound dynamically, which resolves
> the problem. In an interface file, renaming can be banned.
> Can it be banned, for classes, in implementation files?

No need to ban it. Y.g refers to the first X. Simple.


Greg Stein, http://www.lyra.org/