False positive with PY-W2000 on quoted type annotations

False positives of PY-W2000 are found in the following example:

from foo import bar

def func1(arg1: "bar"):
    return arg1

this should not trigger an “Unused Import” and is a valid method of type annotation as described in PEP-484.

Hey @Pilot1782 — thank you for reporting this. We acknowledge it, and will post an update here when we’ve fixed it. For now, you may ignore this issue (docs) if you wish!


The given code should not raise PY-W2000, as we do support parsing annotations as usage of an import. Is this perhaps a simplified version of the code with the false positive?

If possible, can you provide the original code which caused the false positive? It will help us identify the issue on our end.

Yes, this is a very simplified version of the flagged code. Here is a link to the issue.

Here is a quick snippet from the source:

from interactions import (
    Sticker,  # Flagged as unused


class FakeSlash(...):  # New child class

    async def send(  # overridding one of the parent classes methods
        stickers: typing.Optional[
                typing.Iterable[typing.Union["Sticker", "Snowflake_Type"]],  # Not seen
                "Sticker",  # Not seen
        ] = None,

the full source can be found here.

Hey, thanks a lot for the report.

This issue should be fixed now, and all false positives on your dashboard have been removed. Do let us know if it shows up again.