sqlalchemyorg / zimports

Python import rewriter
MIT License
75 stars 6 forks source link

Preserving comments on import lines? (e.g., `# type: ignore`) #5

Open boydgreenfield opened 5 years ago

boydgreenfield commented 5 years ago

Currently, I have a few import lines that are annotated with # type: ignore for mypy, e.g.,:

from boto3.s3.transfer import TransferConfig  # type: ignore
from boto3.session import Session  # type: ignore
import botocore  # type: ignore
import click

Unfortunately, zimports removes those comments and then mypy complains (obviously it'd be better to stub these libraries, but that's somewhat separate). Is there an option to disable this behavior?

I tried doing # noqa # type: ignore but the latter part still gets removed. I'm currently setting them in an if True block, but that feels awfully gross. :/ Appreciate any guidance (and thanks)!

zzzeek commented 5 years ago

unfortunately I don't have a solution for that right now but I will gladly accept a PR that maintains these.

boydgreenfield commented 5 years ago

@zzzeek OK no worries, just thought I might have missed something! I'll put diving in and taking a look on my TODO list... :)

lietu commented 3 years ago

Just bumped into the same issue, # nosec annotation is stripped so can't use zimports