False Negative In rule python:S930

  • SonarQube Community Edition
  • Version 9.3 (build 51899)
  • The code smell “The number and name of arguments passed to a function should match its parameters” is not raised when a method with only positional arguments is called with a missing keyword. Example:

in foo.py:

class Foo:
    def __init__(self, data):
        self.data = data

    def call_method(self, a, b):
       print(self.data, a, b)

in bar.py:

from foo import Foo

class Bar:
    def call_foo(self):
        foo = Foo("my_data")
        foo.call_method(a="positional_a_arg", z="missing_keyword")

This should raise the code smell S930 but does not in our codebase.

Hello @escobar_west,

Thank you for reporting this.

This rule relies on the resolution of the symbol table of the project to work properly. In your example, when the symbol foo.Foo is properly resolved, I confirm that the rule raises the expected issue.

In order for me to further investigate this false negative, I’d need to know more about the project structure (what is the root of the analysis? do you have __init__.py files? etc…). Could you provide me with this info?

It is likely that the module foo.py is resolved to a different fully qualified name than simply foo during the analysis (thus failing to resolve the import in bar.py), but I cannot be sure without more information on the project structure.