[Twisted-Python] Flow: better synchronous exceptions [patch]

Glyph Lefkowitz glyph at twistedmatrix.com
Tue Jun 24 02:30:22 EDT 2003

On Tuesday, June 24, 2003, at 12:42 AM, Clark C. Evans wrote:

>   7.  Most importantly (for me), due to the redundancy of flow/flow.py
>       I'd like to ask glyph if a limited form of __init__.py import
>       could be used in the case of a module/module.py mechansim so
>       that the public objects in module.py could be imported into the
>       module itself.    ie, in flow/__init__.py having:

This is a general problem that needs to be solved within Twisted.  
Packages should be able to specify public interfaces which you can 
import directly, such as

	from twisted.internet import Application
	from twisted.web import Resource
	from twisted.cred import IRealm

These interfaces are generally much smaller than the total of the 
classes in all the modules, and specifying things this way would make 
documentation simpler and allow us to change implementations and 
provide backwards compatibility in a much nicer way.

The problem is that the Python import system does not give us the right 
kind of hooks to provide this without importing things in advance or 
giving a performance hit to objects imported this way (making them 
getattr wrappers), as far as I can tell; while you can patch 
__import__, you can't catch the *first* import mid-way, so if someone 
starts a program with

	from twisted.internet import Application

you could not patch __import__ in twisted/__init__.py because it is not 
called recursively.

I am not opposed to evil in order to make this work, but I am very 
opposed to _fragile_ evil; something as basic as the import system 
should not be prone to surprising behavior and subtle misconfiguration.

So, I am opposed to flow implementing its own ad-hoc name promotion 
until we can come up with a standardizeable way to promote names to the 
package level, but I would very much like to figure out how to promote 
names in a generic way.

More information about the Twisted-Python mailing list