inscrutable error when passing too many parameters
If I do this:
from characteristic import attributes
@attributes(["x"])
class X(object):
pass
X(x=1, y=2)
I get this error:
Traceback (most recent call last):
File "c.py", line 8, in <module>
X(x=1, y=2)
File ".../characteristic.py", line 128, in init
self.__original_init__(*args, **kw)
TypeError: object.__init__() takes no parameters
This isn't a great way of saying parameter "y" not expected.
Yeah, I’m not happy about that either. The problem is that the docs explicitly state that extra parameters are passed to the original __init__.
The original intent was to allow to write own constructors that cooperate with the generated initializer. In retrospect I regret it but I can’t remove it. :-/
Would it be terrible to catch that particular error, and explain it some more? Like add to the message and say that the extra parameters kwargs (display) were passed to the original __init__? Then re-raise?
Hm, how do you mean? Catch TypeErrors and then look at the error message? I mean there are several other error scenarios related to that. :-/
Glyph points the flashlight up under his chin and uses a spooky ghost voice…
inspect.getargspec! Ooooooo!
Inspecting the original __init__'s signature is one way to do it. Another way would be to special-case self.__original_init__[.im_func] is object.__init__, which at least rules out one pretty important case.
OK, feel free to submit a PR. :)
@hynek - any comment on which approach you'd prefer to see? or is it all the same to you?
I think getargspec if you can make it work. That would enable you to raise a meaningful error message.