Extra imports added with libCST 0.3.14 and above
browniebroke opened this issue · comments
Describe the bug
When installing this library fresh with the latest version of libCST (0.3.16 at time of writing), some extra imports are being added to modules which should not be changed.
If I downgrade to libCST 0.3.13, the codemodders work as expected, but from libCST 0.3.14 I can see this odd behaviour.
To Reproduce
On the readthedocs.org codebase:
- Install Django codemod with libCST >= 0.3.14
- checkout source code from https://github.com/readthedocs/readthedocs.org (running on Django 2.2 at the moment)
- Run
djcodemod run --deprecated-in 3.0 .
from the root of the repo
Observe that some empty __init__.py
files have some imports being added e.g.: from django.utils.translation import gettext as _
.
Additional context
Here is the diff between the 2 releases: Instagram/LibCST@v0.3.13...v0.3.14
One thing that stands out: Instagram/LibCST#402
Workaround
We should pin libCST to 0.3.13.
I've added a more minimal test case: https://github.com/browniebroke/django-codemod/blob/main/tests/test_e2e.sh
Works with libCST==0.3.13, breaks with libCST>=0.3.14.
Now fixed with LibCST 0.3.17