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

Andrew Barnert abarnert at yahoo.com
Tue Aug 25 10:35:24 CEST 2015


On Aug 24, 2015, at 19:52, Steven D'Aprano <steve at pearwood.info> wrote:
> 
> I agree that is desirable, but surely many languages have some sort of 
> forward declaration syntax? I know that both the Pascal and C families 
> of languages do.

What would a forward declaration mean in Python?

In C, a forward declaration for a struct tag specifies that it is a struct tag. You can reference "struct spam *" as a type after that, but you can't reference "struct spam", because you need the size for that, which doesn't exist yet. You can't dereference a spam or access a member of a spam. The only thing you know is that a thing called struct spam exists, and is a struct type rather than a function type or native value typedef. That wouldn't do any good in Python.

To be useful, it would have to mean something very different. For example, it could bind the name to some magic marker that means "after something else is bound to this name, go back and fix up everything that made a reference to this magic marker to refer to the bound value instead". (Presumably any method on the marker value just raises a NoValueYetException or something.)



More information about the Python-ideas mailing list