Forum Archive

Autocomplete does not work when using Type Hint (intellisense, Typing)

Vent

I can’t see Autocomplete when using Type Hint.

class Foo():
    def __init__(self):
        self.bar = 'a'
foo = Foo()
foo.# I can get Autocomplete
class Foo():
    def __init__(self):
        self.bar: str = 'a'
foo = Foo()
foo.# There are No Autocomplete

Can I fix it immediately some way? Or Need update from omz?

JonB

Have you tried import typing at the top of your script?

Vent

Now I tried, but the issue is still there...

JonB

Yeah unfortunately the Jedi version used for parsing is old. I'm not sure when Jedi added type hint support, but obviously later.

Vent

Can I update Jedi?

JonB

While you can update Jedi, I don't think that pythonista will use it the updated jedi. But I could be wrong. It actually is possible to swizzle the autocomplete functions, but that might end up being slow. But I'm not sure. I think I had a thread about that a long time back.

I believe the Jedi version we have does support other comment based type definitions.

JonB

Blackmamba I think uses Jedi to allow a "jump to definition" keystroke. You might be able to modify it to have an alternate keystroke to do updated Jedi based completion.

(Blackmamba is on pypi or GitHub. It is basically improvements for using external kb with pythonista )

JonB

https://github.com/zrzka/blackmamba

As a starting point, look at
https://github.com/zrzka/blackmamba/blob/b298bc5d59e5aea9d494282910faf522c08ebba9/blackmamba/script/jump_to_definition.py

I'll have to look to see if I had a autocomplete swizzle.

JonB

https://github.com/jsbain/objc_hacks/blob/master/completer.py

This was an example of how to hook into the pythonista autocomplete system. You would replace the hard coded Suggestions with calls to Jedi.