Anaconda + sublimetext, type of reports indicating errors

I have two python projects in sublimetext3 with anaconda. For some good reason, only in one of them anaconda reports the hint type (PEP 0484) as "invalid syntax" (for both: parameter and function types). What could be the reason?

+5
source share
3 answers

Anaconda PEP-484 application Type hints (influenced by the PEP-3107 Annotation Function and mypy static type checker) apply only to Python 3. I would suggest that the project throws errors in Python 2.

+6
source

To extend the answer to @MattDMo , you can force the Anaconda package to use the python3 interpreter by pressing Cmd / Ctrl + Shift + P , then selecting:

Anaconda: Set Python Interpreter

Then insert the path to your python3 interpreter, which you can find with which python3 :

Be sure to include your virtual path if your code uses packages in virtualenv: /path/to/.virtualenvs/nameofvenv/bin/python3

If you are not using a virtual machine, use your python3 system:

/usr/bin/python3 or /usr/local/bin/python3 for homebrew python3 on mac.

Correctly installing it on python3 should fix the Invalid Syntax error in type annotations.

You can also edit the project file directly to set the interpreter paths:

 { "build_systems": [ { "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "name": "Anaconda Python Builder", "selector": "source.python", "shell_cmd": "\"/path/to/.virtualenvs/venvname/bin/python3\" -u \"$file\"" } ], "settings": { "python_interpreter": "/path/to/.virtualenvs/venvname/bin/python3" } } 
+8
source

To deploy the answer on @Nick Sweeting , remember that Type Hinting was introduced by Python in version 3.5, so if Anaconda uses an interpreter with any previous version of Python3, then it will report Type Hints as invalid syntax. To resolve this, simply install the python interpreter on version 3.5 (or higher).

+1
source

Source: https://habr.com/ru/post/1243507/


All Articles