improve python type suggestion support
Even though I am overall happy about Scala type suggestion, the python one is really weak. It does not take into consideration the fields that I have in my type hints
@antonkulaga Can you please provide an example of the type hints you're defining and the suggestions you expect? Thanks!
@jonathanindig , here is an example: Imaging the following setup
from dataclasses import *
@dataclass
class Bar:
surname: str
def show(self):
print(self.surname)
@dataclass
class Foo:
bar: Bar
name: str
test_foo = Foo(bar = Bar("Surname"), name= "name")
When I type the function:
def test(foo: Foo):
foo.bar.show()
#often (but not always) when I start typing foo. bar is not autosuggested.
#and same for foo.bar.show() show is often not autosuggested
#even though from @dataclass it is well known what fields and functions are!
return foo.bar.surname
I believe this is a limitation of jedi, the library that we use to provide completions (along with everyone else).
See:
>>> from dataclasses import *
>>> @dataclass
... class Bar:
... surname: str
... def show(self):
... print(self.surname)
...
>>> @dataclass
... class Foo:
... bar: Bar
... name: str
...
>>> test_foo = Foo(bar = Bar("Surname"), name= "name")
>>> script = """
... def test(foo: Foo):
... foo."""
>>> jedi.Interpreter(script, [globals()]).complete(len(script.splitlines()), len(script.splitlines()[-1]))
[<Completion: __annotations__>, <Completion: __class__>, <Completion: __dataclass_fields__>, <Completion: __dataclass_params__>, <Completion: __delattr__>, <Completion: __dict__>, <Completion: __dir__>, <Completion: __doc__>, <Completion: __eq__>, <Completion: __format__>, <Completion: __ge__>, <Completion: __getattribute__>, <Completion: __gt__>, <Completion: __hash__>, <Completion: __init__>, <Completion: __init_subclass__>, <Completion: __le__>, <Completion: __lt__>, <Completion: __module__>, <Completion: __ne__>, <Completion: __new__>, <Completion: __reduce__>, <Completion: __reduce_ex__>, <Completion: __repr__>, <Completion: __setattr__>, <Completion: __sizeof__>, <Completion: __str__>, <Completion: __subclasshook__>, <Completion: __weakref__>]
(note that bar and name are missing from the completions).
Try putting the same code into Jupyter and you'll see the same issue (no completions at foo. inside the test()).
That being said, we do have an opportunity here to do better than Jupyter 😄 , as using jedi.Script does seem to get the proper results. We can look into doing that, though integrating the Script API instead of the Interpreter has its own issues to consider as well...
I have created this issue to track that: https://github.com/polynote/polynote/issues/1050
Try putting the same code into Jupyter and you'll see the same issue (no completions at foo. inside the test()).
Well, the key selling point of polynote is beeing better than Jupyter in completions together with better interoperability between languages.
I believe this is a limitation of jedi
Maybe it is possible to open an issue there?