python:S7502 False Positive when using type hints

Please provide

  • Operating system: Ubuntu 25.04
  • SonarQube for VS Code plugin version: 4.35.0
  • Programming language you’re coding in: Python
  • Is connected mode used: No

And a thorough description of the problem / question:

When assigning an asyncio.Task to a variable using type hints, python:S7502 will be raised. For example:

import asyncio


async def my_func() -> None:
    await asyncio.sleep(1)


async def main() -> None:
    my_task: asyncio.Task[None] = asyncio.create_task(my_func())
    await my_task


if __name__ == "__main__":
    asyncio.run(main())

But it is not raised in the following example:

import asyncio


async def my_func() -> None:
    await asyncio.sleep(1)


async def main() -> None:
    my_task = asyncio.create_task(my_func())
    await my_task


if __name__ == "__main__":
    asyncio.run(main())

Hi @MarshTheBacca,
Thanks you for your report.

I was able to reproduce this and created a ticket for it.

Best,
Sebastian Zumbrunn

You need to represent noqa as comment code with proper statement so that sonarlint can identify but that’s not good practice to do in code