Fix kwarg func resolution by jmlidbetter · Pull Request #1136 · pythonnet/pythonnet
@lostmsu here is the breaking test if you fail when a kwarg is supplied that doesn't appear in the method signature:
____________________________________________ test_namespace_and_init _____________________________________________
def test_namespace_and_init():
calls = []
class TestX(System.Object):
__namespace__ = "test_clr_subclass_with_init_args"
def __init__(self, *args, **kwargs):
calls.append((args, kwargs))
> t = TestX(1,2,3,foo="bar")
E TypeError: No constructor matches given arguments: (<class 'int'>, <class 'int'>, <class 'int'>)
src/tests/test_subclass.py:229: TypeError
I haven't done any further investigation into this. I guess there are two ways to proceed:
(1) Log this as an issue and proceed as is
(2) Dig in and fix the broken test
Its up to you, but personally I'm in favour of (1) because (a) having working kwargs (except in the case where you supply extra ones ;) ) is quite a big improvement and (b) python is fairly loose anyway with ducktyping etc etc, in a way all C# methods would have an implicit **kwargs in their signature - it might be possible to throw a warning when extraneous kwargs are given, I don't know.