All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S3801.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

Why is this an issue?

Because it is dynamically typed, Python does not enforce a return type on a function. This means that different paths through a function can return different types of values, which can be very confusing to the user and significantly harder to maintain.

In particular, it is consequently also possible to mix empty return statements (implicitly returning None) with some returning an expression. This rule verifies that all the return statements from a function are consistent.

Noncompliant code example

def foo(a): # Noncompliant, function will return "true" or None
  if a == 1:
    return True
  return

Compliant solution

def foo(a):
  if a == 1:
    return True
  return False

or

def foo(a):
  if a == 1:
    return True
  return None




© 2015 - 2024 Weber Informatics LLC | Privacy Policy