alecthomas / alecthomas/importmagic

Python3 type hint annotations are not considered

Đang mở
#46 4 bình luận 2 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
122
Fork
21
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.