[BUG] References in TypeAlias are not recognized which act as a str
GreyElaina opened this issue ยท comments
Describe the bug
pycln
cannot recognize these references in TypeAlias, which brings unexpected "unused" import removed.
To Reproduce
-
Take this code snippet:
from typing import MutableMapping from typing_extensions import TypeAlias A: TypeAlias = "MutableMapping[str, int]" def a(x: A) -> int: ... ...# other part of this program
-
Run this Pycln command:
$ pycln program.py
-
Error traceback or unexpected output (if present):
program.py:1:0 'from typing import MutableMapping' was removed! ๐ฎ program.py 1 import was removed! ๐ All done! ๐ช ๐ 1 import was removed, 1 file was changed.
-
Unexpected fixed code (if present):
from typing_extensions import TypeAlias A: TypeAlias = "MutableMapping[str, int]" # pyright reports '"MutableMapping" is not defined'
Expected behavior:
-
Description: pycln won't clear these references in TypeAlias which described as a string.
-
Expected output (if present):
Looks good! โจ ๐ฐ โจ 1 file left unchanged.
-
Expected fixed code (if present):
from typing import MutableMapping from typing_extensions import TypeAlias A: TypeAlias = "MutableMapping[str, int]" def a(x: A) -> int: ... ...# other part of this program
Environment (please complete the following informations):
- Python Version: 3.9.10 in pdm's venv
- Pycln Version: v2.1.2
- OS Type: Windows 10
Additional context
None
Hi @GreyElaina, I've just shipped a PR(#190) that has the fix.
Thanks for reporting the bug.