[Twisted-Python] Coding standard question: flowing long imports with parens

Glyph Lefkowitz glyph at twistedmatrix.com
Mon Dec 21 19:55:42 EST 2009

On Dec 21, 2009, at 12:27 PM, Robert Kern wrote:

> On 2009-12-21 10:10 AM, Glyph Lefkowitz wrote:
>> On Dec 21, 2009, at 10:20 AM, James Y Knight wrote:
>>> On Dec 21, 2009, at 12:03 AM, Jonathan Lange wrote:
>>>> Now that we no longer support Python 2.3, may we also allow imports in
>>>> the following style?
>>>> from very.long.package import (
>>>>   bar,
>>>>   foo)
>>> Separating "from X import" and "Y" over a newline totally breaks
>>> grepping for imported modules. 
>> I'm a fan of this style, because it's easier to read and it involves a lot less duplication(...) Anybody want to write a tool which uses the AST to look for name imports?
> Done.

Well, that's certainly a good argument in favor of the abbreviated style, then! :)

> I find this much more robust than grepping the plain text. With all of the 
> variations in the import syntax, it's difficult to find a grep pattern that gets 
> all of the desired imports and rejects enough of the non-import statements. A 
> side effect is that it's easy to get a nice list of all of the import statements 
> in your codebase.
>   $ grinimports.py --no-color ''

This is handy, and a bit more reliable than an unstructured import, but what I *really* want is the ability to say "what depends on this", where "this" is a fully-qualified dotted name in Python.  The weakness of grinimports seems to be that for each additional level of nesting, you need to add an additional regular expression; plus, depending on something could either be importing it, or accessing it as an attribute of a different name that was imported.  Similarly, I have been missing smalltalk's "all senders of" and "all implementors of" functionality since I discovered it many years ago, despite the fact that I never really used Smalltalk for much.  Any chance you have any of those lying around in a different examples directory?

More information about the Twisted-Python mailing list