-
-
Notifications
You must be signed in to change notification settings - Fork 512
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
Completion does not work for generic type aliases #1698
Comments
Thanks for the report, however unfortunately I think you've hit one of the limitations of Python type annotations themselves rather than Jedi specifically. The limitation is that user defined generic aliases (such as your You can see this in action if you add in a I'm pretty sure this is an known issue with the type system, though I can't find an exact reference for it. |
Hmm, I'm not completely understanding your point. User defined generic aliases appear to be supported by mypy and type checking the above example works as expected with mypy (version 0.790). Try changing example 1 to be: from dataclasses import dataclass
from typing import TypeVar, Union
T = TypeVar("T")
MyType = Union[None, T]
@dataclass
class MyDataclass:
t: MyType[str]
a = MyDataclass(t=None)
b = MyDataclass(t="hello")
c = MyDataclass(t=12) and observe that mypy now returns:
This indicates that mypy is understanding the generic type alias as-intended. I do see that |
Huh, looks like you're right. I was fairly sure that this didn't work in the past, though I agree it definitely does now. |
@PeterJCLaw Interested in solving this? Seems like something tailored for you :) |
Looks like this is possible with from typing import Callable, TypeVar
T = TypeVar('T')
MyCallable = Callable[..., T]
x: MyCallable[str]
x().<nothing> I suspect the fix for |
Generic type aliases are not currently supported for autocompletion. For context, for a codebase I'm developing, I'm working with a generic type alias that helps me handle TypeScript interface
undefined
values (which differ fromnull
, a value that corresponds to Python'sNone
).See below for a simple example of the problem.
To remain consistent with jedi's behavior concerning
Union
types, this should provide completions for both string and None, but it completes nothing with version0.17.2
. For comparison, things work fine forOptional
, which is basically a special case ofUnion[None, T]
:The text was updated successfully, but these errors were encountered: