How can I update an attribute created by a base class’ mutable default argument, without modifying that argument? [duplicate]

props should not have a default value like that. Do this instead:

class a(object):
    def __init__(self, props=None):
        if props is None:
            props = {}
        self.props = props

This is a common python “gotcha”.

Leave a Comment