mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Fix signatures for __init__ calls when used with supers, fixes #1163
This commit is contained in:
@@ -222,6 +222,10 @@ class ClassMixin(object):
|
|||||||
next(instance_filters)
|
next(instance_filters)
|
||||||
yield next(instance_filters)
|
yield next(instance_filters)
|
||||||
|
|
||||||
|
def get_signatures(self):
|
||||||
|
init_funcs = self.execute_evaluated().py__getattribute__('__init__')
|
||||||
|
return [sig.bind(self) for sig in init_funcs.get_signatures()]
|
||||||
|
|
||||||
def get_global_filter(self, until_position=None, origin_scope=None):
|
def get_global_filter(self, until_position=None, origin_scope=None):
|
||||||
return ParserTreeFilter(
|
return ParserTreeFilter(
|
||||||
self.evaluator,
|
self.evaluator,
|
||||||
@@ -314,10 +318,6 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBa
|
|||||||
)])
|
)])
|
||||||
return ContextSet({self})
|
return ContextSet({self})
|
||||||
|
|
||||||
def get_signatures(self):
|
|
||||||
init_funcs = self.py__getattribute__('__init__')
|
|
||||||
return [sig.bind(self) for sig in init_funcs.get_signatures()]
|
|
||||||
|
|
||||||
@plugin_manager.decorate()
|
@plugin_manager.decorate()
|
||||||
def get_metaclass_filters(self, metaclass):
|
def get_metaclass_filters(self, metaclass):
|
||||||
debug.dbg('Unprocessed metaclass %s', metaclass)
|
debug.dbg('Unprocessed metaclass %s', metaclass)
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ def test_tree_signature(Script, environment, code, expected):
|
|||||||
('full_redirect(1)', '*args, **kwargs'),
|
('full_redirect(1)', '*args, **kwargs'),
|
||||||
|
|
||||||
# Classes / inheritance
|
# Classes / inheritance
|
||||||
('full_redirect(C)', 'z, *c'),
|
('full_redirect(C)', 'z, *, c'),
|
||||||
('full_redirect(C())', 'y'),
|
('full_redirect(C())', 'y'),
|
||||||
('D', 'D(x, ly)'),
|
('D', 'D(a, z, /)'),
|
||||||
('D()', 'D(x, y)'),
|
('D()', 'D(x, y)'),
|
||||||
('D().foo', 'foo(a, *, bar, z, **kwargs)'),
|
('D().foo', 'foo(a, *, bar, z, **kwargs)'),
|
||||||
|
|
||||||
@@ -166,14 +166,14 @@ def test_nested_signatures(Script, environment, combination, expected, skip_pre_
|
|||||||
return lambda *args, **kwargs: func1(1, 2, 3, 4, *args) + func2(a=3, x=1, y=1, **kwargs)
|
return lambda *args, **kwargs: func1(1, 2, 3, 4, *args) + func2(a=3, x=1, y=1, **kwargs)
|
||||||
|
|
||||||
class C:
|
class C:
|
||||||
def __init__(self, a, z, *c): ...
|
def __init__(self, a, z, *, c): ...
|
||||||
def __call__(self, x, y): ...
|
def __call__(self, x, y): ...
|
||||||
|
|
||||||
def foo(self, bar, z, **kwargs): ...
|
def foo(self, bar, z, **kwargs): ...
|
||||||
|
|
||||||
class D(C):
|
class D(C):
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
super().foo(*args)
|
super().__init__(*args)
|
||||||
|
|
||||||
def foo(self, a, **kwargs):
|
def foo(self, a, **kwargs):
|
||||||
super().foo(**kwargs)
|
super().foo(**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user