== 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 [source,python] ---- ###################### # 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" ---- include::../see.adoc[] ifdef::env-github,rspecator-view[] ''' == Implementation Specification (visible only on this page) === Message * When there is one or more unexpected positional argument: "Remove XXX unexpected argument; 'foo' expects YYY positional arguments." * When there is one or more unexpected named argument: "Remove this unexpected named argument X" * When the maximum number of positional arguments is reached and {empty}*args is given: "Remove "*XXX"; maximum number of positional arguments already reached." * When the maximum number of keyword arguments is reached and {empty}*{empty}*kwargs is given: "Remove "**XXX"; maximum number of keyword arguments already reached." * When there are missing positional arguments: "Add XXX missing arguments; 'foo' expects YYY positional arguments." * When there are missing keyword arguments: "Add the missing keyword argument XXX" === Highlighting Primary: The function name Secondary: * The function definition ''' == Comments And Links (visible only on this page) include::../comments-and-links.adoc[] endif::env-github,rspecator-view[]