Wrong name for an argument in a class instantiation¶
ID: py/call/wrong-named-class-argument Kind: problem Severity: error Precision: very-high Tags: - reliability - correctness - external/cwe/cwe-628 Query suites: - python-security-and-quality.qls
Using a named argument whose name does not correspond to a parameter of the
__init__ method of the class being instantiated, will result in a
TypeError at runtime.
Check for typos in the name of the arguments and fix those. If the name is clearly different, then this suggests a logical error. The change required to correct the error will depend on whether the wrong argument has been specified or whether the wrong class has been specified.
class Point(object): def __init__(self, x, y): self.x = x self.y = y p = Point(x=1, yy=2) # TypeError: 'yy' is not a valid keyword argument