diff --git a/jedi/evaluate_representation.py b/jedi/evaluate_representation.py index 74ce5b46..82d2a034 100644 --- a/jedi/evaluate_representation.py +++ b/jedi/evaluate_representation.py @@ -288,7 +288,8 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.IsScope)): def __getattr__(self, name): if name not in ['start_pos', 'end_pos', 'parent', 'asserts', 'docstr', - 'get_imports', 'get_parent_until', 'get_code', 'subscopes']: + 'doc', 'get_imports', 'get_parent_until', 'get_code', + 'subscopes']: raise AttributeError("Don't touch this: %s of %s !" % (name, self)) return getattr(self.base, name) diff --git a/jedi/parsing_representation.py b/jedi/parsing_representation.py index c3fa3aa3..3df46239 100644 --- a/jedi/parsing_representation.py +++ b/jedi/parsing_representation.py @@ -346,6 +346,18 @@ class Class(Scope): string += "pass\n" return string + @property + def doc(self): + """ + Return a document string including call signature of __init__. + """ + for sub in self.subscopes: + if sub.name.names[-1] == '__init__': + return '%s\n\n%s' % ( + sub.get_call_signature(funcname=self.name.names[-1]), + self.docstr) + return self.docstr + class Function(Scope): """ @@ -394,16 +406,18 @@ class Function(Scope): debug.warning("multiple names in param %s" % n) return n - def get_call_signature(self, width=72): + def get_call_signature(self, width=72, funcname=None): """ Generate call signature of this function. :param width: Fold lines if a line is longer than this value. :type width: int + :arg funcname: Override function name when given. + :type funcname: str :rtype: str """ - l = self.name.names[-1] + '(' + l = (funcname or self.name.names[-1]) + '(' lines = [] for (i, p) in enumerate(self.params): code = p.get_code(False) diff --git a/test/regression.py b/test/regression.py index 314dde67..223c5c56 100755 --- a/test/regression.py +++ b/test/regression.py @@ -98,6 +98,15 @@ class TestRegression(TestBase): doc = defs[0].doc assert "f(x, y = 1, z = 'a')" in doc + def test_class_call_signature(self): + defs = self.definition(""" + class Foo: + def __init__(self, x, y=1, z='a'): + pass + Foo""") + doc = defs[0].doc + assert "Foo(self, x, y = 1, z = 'a')" in doc + def test_definition_at_zero(self): assert self.definition("a", (1, 1)) == [] s = self.definition("str", (1, 1))