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

Strangely, cannot recognize function with type hinting. #1198

Closed
nasyxx opened this Issue Aug 13, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@nasyxx
Copy link

nasyxx commented Aug 13, 2018

Strangely, cannot recognize function with type hinting.

My emacs cannot understand functions with type hinting. After a lot of troubleshooting, I found out that it was a problem with jedi. I am not sure what's wrong with it, due to everything works well on another machine.

The test source string:

"""def with_hints(a: int, b: int) -> None:
    return None


def without_hints(a, b):
    return None


with"""

On my macOS:

λ pip3 show jedi
Name: jedi
Version: 0.12.1
Summary: An autocompletion tool for Python that can be used for text editors.
Home-page: https://github.com/davidhalter/jedi
Author: David Halter
Author-email: xxx
License: MIT
Location: /usr/local/lib/python3.7/site-packages
Requires: parso
Required-by: python-language-server, ptpython, ipython
Python 3.7.0 (default, Aug 13 2018, 03:32:41) 
[Clang 10.0.0 (clang-1000.10.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import jedi
>>> sss = """def with_hints(a: int, b: int) -> None:
...     return None
... 
... 
... def without_hints(a, b):
...     return None
... 
... 
... with"""
>>> a = jedi.Script(source=sss, column=4, line=9)
>>> a.completions()
[<Completion: with>, <Completion: without_hints>]

On my Gentoo:

λ pip3.7 show jedi                                                                                                                                                       
Name: jedi
Version: 0.12.1
Summary: An autocompletion tool for Python that can be used for text editors.
Home-page: https://github.com/davidhalter/jedi
Author: David Halter
Author-email: xxx
License: MIT
Location: /root/.local/lib/python3.7/site-packages
Requires: parso
Required-by: 
Python 3.7.0 (default, Aug 11 2018, 12:49:28) 
[Clang 6.0.1 (tags/RELEASE_601/final)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jedi
>>> sss = """def with_hints(a: int, b: int) -> None:
...     return None
... 
... 
... def without_hints(a, b):
...     return None
... 
... 
... with"""
>>> a = jedi.Script(source=sss, column=4, line=9)
>>> a.completions()
[<Completion: with>, <Completion: with_hints>, <Completion: without_hints>]

You can easily found out <Completion: with_hints> is missing on macOS.

@davidhalter

This comment has been minimized.

Copy link
Owner

davidhalter commented Aug 13, 2018

Can you try with non-Python3.7? It's not yet supported. Your only Python on Mac might be 2.7 and 3.7, which then makes Jedi choose Python 2.7, because it doesn't work with 3.7, yet.

@nasyxx

This comment has been minimized.

Copy link
Author

nasyxx commented Aug 13, 2018

Hi, here is the result:

The built-in python2.7:

(btw, I am on macOS Mojave.)

λ /usr/bin/python
Python 2.7.10 (default, Jul 21 2018, 17:30:42) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import jedi
>>> sss = """def with_hints(a: int, b: int) -> None:
...     return None
... 
... 
... def without_hints(a, b):
...     return None
... 
... 
... with"""
>>> a = jedi.Script(source=sss, column=4, line=9)
>>> a.completions()
[<Completion: with>, <Completion: without_hints>]

python2.7 from homebrew:

λ python
Python 2.7.15 (default, Jul 22 2018, 09:56:02) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import jedi
>>> sss = """def with_hints(a: int, b: int) -> None:
...     return None
... 
... 
... def without_hints(a, b):
...     return None
... 
... 
... with"""
>>> 
>>> a = jedi.Script(source=sss, column=4, line=9)
>>> a.completions()
[<Completion: with>, <Completion: without_hints>]

pyenv python3.6.6 works.

λ pyenv exec python
Python 3.6.6 (default, Aug  3 2018, 18:10:32) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import jedi
>>> sss = """def with_hints(a: int, b: int) -> None:
...     return None
... 
... 
... def without_hints(a, b):
...     return None
... 
... 
... with"""
>>> a = jedi.Script(source=sss, column=4, line=9)
>>> a.completions()
[<Completion: with>, <Completion: with_hints>, <Completion: without_hints>]
@davidhalter

This comment has been minimized.

Copy link
Owner

davidhalter commented Aug 13, 2018

The point is that in Python2.7 it will never work (because it doesn't support type hints). In Python 3.6 it works and in 3.7 it won't, because it's not supported yet.

Please watch #1096 to wait for 3.7 support.

@nasyxx

This comment has been minimized.

Copy link
Author

nasyxx commented Aug 13, 2018

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment