forked from VimPlug/jedi
Implement __new__ signatures, fixes #2073
This commit is contained in:
@@ -378,6 +378,18 @@ class ClassMixin:
|
|||||||
return sigs
|
return sigs
|
||||||
args = ValuesArguments([])
|
args = ValuesArguments([])
|
||||||
init_funcs = self.py__call__(args).py__getattribute__('__init__')
|
init_funcs = self.py__call__(args).py__getattribute__('__init__')
|
||||||
|
if len(init_funcs) == 1:
|
||||||
|
init = next(iter(init_funcs))
|
||||||
|
try:
|
||||||
|
class_context = init.class_context
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# In the case where we are on object.__init__, we try to use
|
||||||
|
# __new__.
|
||||||
|
if class_context.get_root_context().is_builtins_module() \
|
||||||
|
and init.class_context.name.string_name == "object":
|
||||||
|
init_funcs = self.py__call__(args).py__getattribute__('__new__')
|
||||||
|
|
||||||
dataclass_sigs = self._get_dataclass_transform_signatures()
|
dataclass_sigs = self._get_dataclass_transform_signatures()
|
||||||
if dataclass_sigs:
|
if dataclass_sigs:
|
||||||
|
|||||||
@@ -27,6 +27,17 @@ def test_valid_call(Script):
|
|||||||
assert_signature(Script, 'bool()', 'bool', column=5)
|
assert_signature(Script, 'bool()', 'bool', column=5)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dunder_new(Script):
|
||||||
|
# From #2073
|
||||||
|
s = dedent("""\
|
||||||
|
from typing import Self
|
||||||
|
class C:
|
||||||
|
def __new__(cls, b) -> Self:
|
||||||
|
pass
|
||||||
|
C( )""")
|
||||||
|
assert_signature(Script, s, 'C', 0, line=5, column=2)
|
||||||
|
|
||||||
|
|
||||||
class TestSignatures(TestCase):
|
class TestSignatures(TestCase):
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def init(self, Script):
|
def init(self, Script):
|
||||||
|
|||||||
Reference in New Issue
Block a user