Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve unexpected token parser 16 visual studio code

When I am writing Python in V.S. Code, I keep getting errors that highlight a good portion of my code base. IntelliCode shows an error message that reads:

"unexpected token '=' Python(parser-16)"

So, it appear to stem specifically from specific lines, and when the lines are copy & pasted they inherit the errors, however; if you type-out the line anew, the error is resolved? It is a perplexing issue.

enter image description here

like image 565
Hellfire Avatar asked Oct 14 '22 22:10

Hellfire


1 Answers


There are 3 things that could be


The first is simple, restart your editor and see if the issue persists.


The second thing it could be is an old unmaintained extension:


Installing the wrong extensions can cause headaches and hard-to-solve issues. This is why installing extensions because it's fun, and they are free, is a bad idea. You should always have a decent reason for installing an extension, and should always avoid installing an extension under the pretense that you may, one day, need it.

When it comes to an opensource editor like VSCode, extensions are Hit & miss, which is, to say the least. Sometimes you might find a hidden-gem, or something new the surprises you unexpectedly in a good way, but you need to have a reason to be looking for a specific extension because you need to know what your look for, many extensions offer features that VSCode now supports out of the box, some extensions haven't been upgraded for 2-3 years, and are full of deprecated code. There is an example of a repository that was maintained by Microsoft up until 2020. People are still creating issues that reference parser 16 errors, and they only get a response that the repository is no longer maintained, and a suggestion to use a different tool."_

Here's the link to the repository I mentioned above. I don't know what extensions you are using, but if it uses this old language server repo, which is for some reason still active, you will want to swap out that extension for something else, or just toss it all together.


To test if it is an extension perform the simple steps below:


To confirm that it is an extension...

  1. OPEN Your Project inside of V.S. Code

  2. HIT F1 to open up your quick input menu

  3. TYPE: "Reload window with extensions disabled"

  4. SELECT the command from the menu that matches the text you typed in step-3 above ("Reload Window with Extensions Disabled") (or workbench.action.reloadWindowWithExtensionsDisabled)

  5. After the editor reloads check your and see if the issue persists.



The problem should go away, as you shouldn't have syntax highlighting from an extension enabled. You need to accomplish having Syntax Highlighting W/O having the issue though. To do this you're going to temporarily leave all of your extensions disabled, then, if you don't have it, install the extension pack that is called:

  • Python (that's it, its just called "Python").

If you do have it, then just enable it. The V.S. Code Python Extension adds Microsoft support to V.S. Code for Python. Make sure that the extension ID-Name is ms-python. python, that it was developed by Microsoft, and that you have the latest version.

After you have your project open with all extensions, except for the Microsoft Python extension installed, see if the issue is gone and that your syntax highlighting works.



The third and last thing it could be is the Python Extensions parser is unable to parse your code, which may, or may not be your fault.


If the above did not solve your issue then it's likely that the issue is a problem with your code, which may, or may not, be your fault. Python syntax is funny, as it's far different than other c-style languages, yet it is still very much C-style. In the past, I have seen parser 16 errors caused by F-strings, and R-Strings, because of bugs in the parser. They either had a hard time picking up multiple quotes """ in a row, or they had a hard time, picking up a logic-operator with multiple quotes, the syntax written like the following example would cause an error in specific use cases:

"""!==

You need to go through, make sure it's not a mistake on your end, you can even post your code here, which would help the community to determine if its a bug, especially if you can confirm for us that you have only the python extension active while you are getting the error.

If you determine that your codebase is in working order, and if you are right, it is in working order, then it is likely a bug, but you need to like really, really be sure. Once you are sure, go to the following repository and create an issue.

VSCode-Python Repository (CLICK HERE)
like image 50
j D3V Avatar answered Oct 27 '22 16:10

j D3V