hadialqattan / pycln

A formatter for finding and removing unused import statements.

Home Page:https://hadialqattan.github.io/pycln

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] inlined with ':' for linters and type checkers

cheginit opened this issue · comments

Describe the bug A clear and concise description of what the bug is.
pycln throws an UnsupportedCase if there's any : in the import statement. But there
are cases where we want to provide a comment to a linters or type checkers, like so:
import numpy # type: ignore.

To Reproduce Steps to reproduce the behavior:

  1. Take this code snippet:

    try:
        import numpy  # type: ignore
    except ImportError:
        numpy = None
  2. Run this Pycln command:

    $ pycln
  3. Error traceback or unexpected output (if present):

    UnsupportedCase: an import statement inlined with ':'. ⛔
  4. Unexpected fixed code (if present):

Expected behavior:

  1. Description: A clear and concise description of what you expected to happen.
    It would be helpful if using colon for after # is allowed.

  2. Expected output (if present):

  3. Expected fixed code (if present):

Environment (please complete the following information):

  • Python Version: Any
  • Pycln Version: v2.1.2
  • OS Type: macOS

Additional context Add any other context about the problem here.

encountered the same, workaround with # nopycln: import. (https://hadialqattan.github.io/pycln/#/?id=pycln-skips)

Hi @cheginit, briefly, the case was that Pycln was classifying comments with a colon or a semicolon as unsupported cases false positively... I've just shipped a PR(#189) that has the fix.

Thanks for reporting the bug.

That's great! Appreciate it.