Comment 9 for bug 1023236

Revision history for this message
Russell Sim (russell-sim) wrote : Re: [Bug 1023236] Re: py-find-imports can't handle multiline imports or comma separated imports

Andreas Roehler <email address hidden> writes:

> you are referring to compound statements, while py-end-of-statement
> deals with simple statement.

> Rusell provided a solution for a special case, which is okay. However,
> seen from this point, it's probable, there might be more and other
> special cases: blank lines, comments , lists over multiple lines etc.

We could perhaps copy the data out to a temporary buffer and use find
and replace to change the ; characters to newlines. That should make it
work for *most* other cases.

I agree, probably one of the harder to parse forms will be.

from os import (mknod, # import for later
     open, # another interesting import
     path) # import completed

So perhaps copy interesting lines to temporary buffer:
1. Trim comments
2. split the lines with a ;
3. Delete the string \\\n from the buffer
4. Parse with a simple regex for most of the imports.
4. Parse with a regex that will work over multiple lines with ()

The only thing that wont be handled will be conditional import, so I
guess it's best to leave them out for the time being.

I'll make a branch see what I can put together....