Is self.__dict__.update(**kwargs) good or poor style?

class Shape(object):
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y

class Circle(Shape):
    def __init__(self, r=None, **kwargs):
        super(Circle, self).__init__(**kwargs)
        self.r = r

And this is it. Don’t use **kwargs when you don’t really need them.

Is this considered a cheat or is this good style (as long as the
interface to Circle is well-documented)?

When you have a choice between writing a simple, understandable code and headache code + nice docstrings, you actually don’t have any choices, you just go and write simple, self-documented code:)

Leave a Comment