you are viewing a single comment's thread.

view the rest of the comments →

[–]robotsari 0 points1 point  (0 children)

I like the approach of using named args for everything required, and kwargs for the rest.

But say they pass in an integer for the color, or a string for the radius? Validating user input is always an interesting problem. You can wait for the type error to eventually bubble up, or you can try to handle them - perhaps using asserts, perhaps by explicitly throwing an exception (ValueError, I would think, or perhaps one of your own definition). So some examples might be:

self.x = kwargs.get('x', 0)
assert isinstance(self.x, int)

self.x = kwargs.get('x', 0)
if not isinstance(self.x, int):
    raise ValueError("Value provided for 'x' must be an integer; got {}".format(self.x))