alecthomas / alecthomas/importmagic

Imports block detection needs to be smarter

オープン
#8 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
122
フォーク
21
PR マージ指標
30日以内にマージされた PR はありません

説明

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:

``` python
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

``` python
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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。