org.sonar.l10n.py.rules.python.S930.html Maven / Gradle / Ivy
Why is this an issue?
Calling a function or a method with fewer or more arguments than expected will raise a TypeError
. This is usually a bug and should be
fixed.
Noncompliant code example
######################
# Positional Arguments
######################
param_args = [1, 2, 3]
param_kwargs = {'x': 1, 'y': 2}
def func(a, b=1):
print(a, b)
def positional_unlimited(a, b=1, *args):
print(a, b, *args)
func(1)
func(1, 42)
func(1, 2, 3) # Noncompliant. Too many positional arguments
func() # Noncompliant. Missing positional argument for "a"
positional_unlimited(1, 2, 3, 4, 5)
def positional_limited(a, *, b=2):
print(a, b)
positional_limited(1, 2) # Noncompliant. Too many positional arguments
#############################
# Unexpected Keyword argument
#############################
def keywords(a=1, b=2, *, c=3):
print(a, b, c)
keywords(1)
keywords(1, z=42) # Noncompliant. Unexpected keyword argument "z"
def keywords_unlimited(a=1, b=2, *, c=3, **kwargs):
print(a, b, kwargs)
keywords_unlimited(a=1, b=2, z=42)
#################################
# Mandatory Keyword argument only
#################################
def mandatory_keyword(a, *, b):
print(a, b)
mandatory_keyword(1, b=2)
mandatory_keyword(1) # Noncompliant. Missing keyword argument "b"
Resources
© 2015 - 2024 Weber Informatics LLC | Privacy Policy