False positive asyncio.run loop_factory

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for? Python
  • Which rule? Remove this unexpected named argument ‘loop_factory’.sonarlint(python:S930)
  • Why do you believe it’s a false-positive/false-negative? Python 3.12 asyncio.run() has a named argument loop_factory
  • Are you using
    • SonarCloud? Yes (no idea what version, but we see the error today, yesterday and as far back as several weeks ago if memory serves)
    • SonarLint - which IDE/version? Yes
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
import asyncio


async def foo():
    pass


asyncio.run(foo(), loop_factory=None)

this gives no false positive outside of my project, but does give the false positive inside the project. sonarlint complains about foo() needing a comment explaining the pass both inside and outside the project.

The only sonarqube related project configuration I can think of is sonarproject.properties which I can’t fully share but contains this line:

sonar.python.version=3.12

(and later we tried upping it to 3.13 just in case, same problem)

which suggests to me that it should use python 3.12 to determine what named arguments are used by functions in the stdlib. I wouldn’t be surprised if something is wrong with our configuration but we’re stuck as to what that might be.

EDIT: simplified the reproduction code, I complicated it further before I realised that I only got the false positive inside of our project.

Hey there.

This isn’t really a Yes/No question :smiley:

Ha fair, my sonarlint is the vscode extension and is version… 4.12

Hi David,
Thanks for your report.

Unfortunately, this is a known issue. While we do use the Python version to determine which stubs to load, we don’t have stubs for Python 3.12 and 3.13 yet. Instead, we’re falling back to the Python 3.11 stubs, where the loop_factory keyword doesn’t exist. Hence the false positive you reported.

Here’s the Jira ticket tracking the generation of the stubs: SONARPY-1522

With best regards,
Sebastian Zumbrunn

1 Like