[Python-ideas] Forward-References & Out-of-order declaration
Andrew Barnert
abarnert at yahoo.com
Tue Aug 25 23:17:22 CEST 2015
On Aug 25, 2015, at 11:03, Sven R. Kunze <srkunze at mail.de> wrote:
>
> While reading material for implementing some kind of import hooks and so forth for the xfork package, I came across this one:
> http://stackoverflow.com/questions/16907186/python-model-inheritance-and-order-of-model-declaration
>
> Reactivated in my mind, after reading Prof. Humbert's request of adding a "more forwarded" referencing of classes, I just wanted to ask:
>
> 1) What is the general opinion regarding having a more declarative style when writing modules?
> 2) That given, what is the general opinion about introducing the out-of-order declaration asked for in the StackOverflow posts?
The fact that the global namespace is imperative rather than declarative means that you can use functions and classes in defining later functions, classes, and constants. This is essential for features like decorators, metaclasses, dynamically-generated types liked namedtuples, etc.
Sure, you could probably come up with ways to replace all of those features with similar features that didn't require the existing implementation (make everything lazy, use a two-level store, or just come up with special-purpose workarounds for each feature), or require users to do things differently (e.g., you can only use decorators imported from a separate scope), but that would be a pretty different language.
More information about the Python-ideas
mailing list