alecthomas / alecthomas/importmagic

Python3 type hint annotations are not considered

Ouverte
#46 4 commentaires 2 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
122
Forks
21
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.