importmagic icon indicating copy to clipboard operation
importmagic copied to clipboard

Imports block detection needs to be smarter

Open DamnWidget opened this issue 11 years ago • 3 comments

The current imports block detection need to be improved, for example, this is a typical and common import block in applications that supports several versions of some library or different versions of python even:

try:
    import ujson as json
except ImportError:
    import json

from collections import defaultdict
import sys

def main():
    print(os.uname())
    a = defaultdict(list)

This is translated to

import json
import sys
from collections import defaultdict

import ujsonas json


try:
    import ujson as json
except ImportError:
    import json

from collections import defaultdict
import sys

def main():
    print(os.uname())
    a = defaultdict(list)

That is a complete disaster, in the other hand, the scope is fine:

print(scope.find_unresolved_and_unreferenced_symbols())
(set(['os.uname']), set(['sys', 'json', 'main']))

The importer has no clue about what is really imported in the file as its not able to know where the imports block really ends.

DamnWidget avatar Nov 16 '14 20:11 DamnWidget

Agreed, the recognition of the import blocks (especially with alternates) is currently not smart enough.

birkenfeld avatar Nov 16 '14 21:11 birkenfeld

I am working on this btw

DamnWidget avatar Nov 16 '14 22:11 DamnWidget

any updates?

ChillarAnand avatar Mar 19 '17 06:03 ChillarAnand