If an instance method is called 'directly' through the class, like this: class MyClass: def method(self, arg1): pass obj = MyClass() MyClass.method(obj, 42) The argument type is deduced wrong. It thinks the 'obj' argument matches with the 'arg1' parameter, but it should be matched with 'self'. This means it deduces 'arg1' to be of type 'MyClass', when it should be 'int'. A notable common case where this causes problems is when a constructor calls the constructor of the base class: class Base: def __init__(self, foo): self.foo = foo class Derived(Base): def __init__(self, foo): Base.__init__(self, foo) # ...more Derived-specific initialization... Now it thinks Base.__init__'s 'foo' argument is of type 'Derived', which also affects the type of the 'foo' attribute of the object, which cascades into breaking types in many other places :(
Yep, need to fix that. Thanks for the comprehensible report.
Git commit b36edbb6c54a462cc6d72c344c0f760d5a7c2248 by Francis Herne. Committed on 14/12/2016 at 09:07. Pushed by flherne into branch 'master'. Skip explicit `self` argument when calling via class. Instance methods can be called via the class: `Class.method(instance, arg)` Self arguments are handled separately. With an explicit `instance` argument as in the example, its type was wrongly used for the next argument with all subsequent argtypes offset by one. Simply skip such arguments where they exist. Test `method_explicit_self` previously failed, now passes. Test `parent_constructor_arg_type` previously failed. Now it fails on the first run, but gets the correct type if reloading the document. Probably related to https://bugs.kde.org/show_bug.cgi?id=306213 Other new tests passed already. No test regressions. M +21 -9 duchain/declarationbuilder.cpp M +29 -0 duchain/tests/pyduchaintest.cpp https://commits.kde.org/kdev-python/b36edbb6c54a462cc6d72c344c0f760d5a7c2248
Your actually-useful example still doesn't work properly - the type of Base.foo won't be found unless the document is reparsed another couple of times, e.g. by hitting F5. See https://bugs.kde.org/show_bug.cgi?id=306213