Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depedently typed function overloads returns are treated as unions #2028

Open
SlayerOfTheBad opened this issue Oct 18, 2024 · 1 comment
Open
Labels

Comments

@SlayerOfTheBad
Copy link

SlayerOfTheBad commented Oct 18, 2024

This is likely related to #1416 , hence the similar naming.

I have the following file

from typing import overload

class Foo:
    pass

class FooBuilder:
    def func_foo(self):
        pass

class Bar:
    pass

class BarBuilder:
    def func_bar(self):
        pass

@overload
def get_obj(input: type[Foo]) -> FooBuilder: ...

@overload
def get_obj(input: type[Bar]) -> BarBuilder: ...

def get_obj(input: type):
    pass

builder = get_obj(Foo)
builder

Using pylsp (which uses Jedi for its completion) in neovim, I get suggested the functions for both FooBuilder and BarBuilder.

image

The example in #1416 does work, so I know I've got that fix integrated in my system.
Because of this, I assume this has something to do with type[T] resolution, rather than overload resolution.

Version:

jedi                  0.19.1
@PeterJCLaw
Copy link
Collaborator

PeterJCLaw commented Oct 19, 2024

From a quick look I suspect this could be a more general issue with how type is handled. For example the following also fails:

from typing import overload

class Custom: pass

@overload
def func_a(x: type[Custom]) -> int:
    ...

@overload
def func_a(x: float) -> str:
    ...

def func_a(x):
    pass

t: type[Custom]

j = func_a(t)
j

When running this under sith.py with debugging enabled we get a warning which seems to stem from trying to execute type(..) as part of setting up the annotation to t. I'm not sure if that's actually related to the overloads issue though, since just inferring the type of t (again via sith) does seem to get the right result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants