mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-06 20:24:00 +08:00
Implement __new__ signatures, fixes #2073
This commit is contained in:
@@ -378,6 +378,18 @@ class ClassMixin:
|
||||
return sigs
|
||||
args = ValuesArguments([])
|
||||
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()
|
||||
if dataclass_sigs:
|
||||
|
||||
@@ -27,6 +27,17 @@ def test_valid_call(Script):
|
||||
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):
|
||||
@pytest.fixture(autouse=True)
|
||||
def init(self, Script):
|
||||
|
||||
Reference in New Issue
Block a user