6 New Rules to Support Python Type Hints

Hello Python users,

We have a new set of rules in our Python analysis to ensure the use of type hints result in expected behaviors.

These are the new rules:

  • S6538: Function returns should have type hints
  • S6540: Function parameters should have type hints
  • S6542: “Any” should not be used as a type hint
  • S6543: Type hints of generic types should specify their type parameters
  • S6545: Built-in generic types should be preferred over the typing module in type hints
  • S6546: Union type expressions should be preferred over “typing.Union” in type hints

As type hinting is optional, these rules will need to be activated for those who use Python type hinting.
These rules are available now on SonarCloud and will be available on SonarQube 10.1.

Your feedback is appreciated.




For Python static code analysis we enabled this on our project:

However, I would like to disable this rule for Unit/Integration tests where a Function (In most scenarios) is None. I would prefer to not require adding it to every test.

For functions where we are actually returning something (ie: A yield or return keywords) I do want to enforce the rule.