Mutable default argument (ARCH2194)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key python.quality.mutable-default-arg · Severity warning · Category quality
Python default arguments are evaluated once at definition time; a mutable default is shared across every call, causing a classic bug. Use None instead.
Incorrect
Section titled “Incorrect”def add_item(item, bucket=[]): bucket.append(item) return bucketCorrect
Section titled “Correct”def add_item(item, bucket=None): if bucket is None: bucket = [] bucket.append(item) return bucketDefault to None and create the new mutable object inside the body.