alecthomas / alecthomas/importmagic

Imports block detection needs to be smarter

未关闭
#8 3 条评论 0 个 reaction 已指派 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 摘要。