alecthomas / alecthomas/importmagic

Python3 type hint annotations are not considered

未关闭
#46 4 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
122
派生
21
PR 合并指标
30 天内没有已合并 PR

描述

Hi, thanks for the great project.

Currently it seems that importmagic doesn't look for `__annotations__` properties added in recent version of python 3, so python3 syntax-aware checkers complain if I use a type hint without importing the name, but importmagic will delete any import that's only referenced in a type annotation.

Test case:
```python
import importmagic

code = """
from typing import Iterable

def print_it(it: Iterable):
for i in it:
print(i)

print_it(['a', 'b', 'c'])
"""

scope = importmagic.Scope.from_source(code)
unresolved, unreferenced = scope.find_unresolved_and_unreferenced_symbols()
print("unreferenced: {}".format(unreferenced))

from typing import Iterable

def print_it(it: Iterable):
for i in it:
print(i)

print("function annotation: {}".format(print_it.__annotations__))
```

Output:
```
$ python3 importmagictest.py
unreferenced: {'Iterable'}
function annotation: {'it': typing.Iterable<+T_co>}
```

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。