Type hint produces Syntax error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Type hint produces Syntax error (/thread-9723.html) |
Type hint produces Syntax error - Digamma - Apr-25-2018 Hi, I use PyCharm and a venv based on Python 3.7 I want to use type hint : def some_function(some_arg: str) -> bool: return "some_str" == some_argCode inspection doesn't reveal any suspicious code But : Does someone have any idea why please ?
RE: Type hint produces Syntax error - buran - Apr-25-2018 Please post full traceback, not just the last line RE: Type hint produces Syntax error - Digamma - Apr-26-2018 Sorry, here is the full traceback :
RE: Type hint produces Syntax error - snippsat - Apr-26-2018 You are not running 3.7 rather 2.7. You should check python and pip in virtual environment (venv) that you have created.# Running 2.7 get this error E:\1py_div λ py -2.7 type_hint.py File "type_hint.py", line 1 def some_function(some_arg: str) -> bool: ^ SyntaxError: invalid syntax E:\1py_div λ python -V Python 3.6.4 # Check pip in venv it should not point to OS Python E:\1py_div λ pip -V pip 10.0.1 from c:\python36\lib\site-packages\pip (python 3.6) # Check placement in venv it should not point to OS Python E:\1py_div λ python -c "import sys; print(sys.executable)" C:\python36\python.exe # Now running 3.6 there is no error E:\1py_div λ python type_hint.pyPyCharm Configuring Python Interpreter. RE: Type hint produces Syntax error - Digamma - Apr-27-2018 Thanks ! (venv) [...]>python -c "import sys; print(sys.executable)" [...]\venv\Scripts\python.exe (venv) [...]>pip -V pip 9.0.1 from [...]\venv\lib\site-packages\pip-9.0.1-py3.7.egg (python 3.7) (venv) [...]>python -V Python 3.7.0b3 (venv) [...]>venv\Scripts\python.exe type_hint_test.py (venv) [...]> Thanks !The venv is really based on python 3.7 but I wasn't using it to start the script. |