davidhalter / jedi

Awesome autocompletion, static analysis and refactoring library for python
http://jedi.readthedocs.io
Other
5.82k stars 507 forks source link

Does Jedi support type inference for type annotations that include generics? #1992

Closed WutingjiaX closed 7 months ago

WutingjiaX commented 7 months ago

I have an example like this:

from dataclasses import dataclass
from typing import Dict

@dataclass
class MyClass:
    id_to_name: Dict[int, str]

my_instance = MyClass(id_to_name={1: "Alice", 2: "Bob"})
my_instance.id_to_name

then I want to infer the type of id_to_name with infer() API。But the result is: image

It loses the generic info。

update: I find that to access some protected Attribute,I can get generic info,like this: img_v3_02ae_5b593dca-54e3-4b8e-a878-9b27b3bf60dg

But why wasn't this information serialized into the name or full_name fields?

davidhalter commented 7 months ago

I assume however that my_instance.id_to_name[0] is working though? Jedi does not currently give you the generics as part of full_name or anything else. That's just a visual limitation. However AFAIK generics should still work in that case for autocompletion/type inference.

WutingjiaX commented 7 months ago

thx~