Pycharm is generating language errors for Python version 3.6 although interpreter is 3.9

Viewed 125

The language interpreter is set to a Python 3.9 version:

Python 3.9 interpreter

But a Python scratch file is being parsed by some kind of 3.6 interpreter:

Complaint about 3.6 language features

Note that I created in two different scratch files and the same error occurs. Why would this happen and is there a workaround [short of creating an entirely new project from scratch]?

I am on Pycharm Professional 2021.3.1

Update based on answer by @TurePaisson he though maybe the Code is compatible with specific Python were set. That was a shrewd guess - but turns out I have not set that:

enter image description here

enter image description here

Update The following snippet can be used to test python3.6 vs 3.8+

x = (y := 3) + 7 
4 Answers

In the preferences dialog, search for "versions" and you will find, under Editor/Inspections, an inspection "Code is compatible with specific Python versions" with checkboxes for which versions to check against.

I ended up creating a new python interpeter with version 3.9 and selecting it for the project interpreter. There's clearly some bug within Pycharm that it does not always cleanly switch among interpeters/versions - so starting from scratch is sometimes apparently needed.

I'll start by saying that I tried googling the exact error message and there aren't any significant hits (that's reason alone to post this leaving it as a roadsign):

"Python version 3.6 does not support assignment expressions"

I tried this with PyCharm versions 2021.2.2, 2021.2.4 and 2022.1 Pro (switching between Python 3.6 and Python 3.9) but I wasn't able to reproduce the exact problem that's shown in the question (I was unable to update to the exact 2021.3.1) and there might be some Project setting that's not obvious.

So I have 2 hunches:

  1. It's possible there's something stuck with the inspection profiles since the OP seems to be working from a repository.

  2. From experience my next guess would be to try and change the interpreter version of the "run configuration" because it's not stated explicitly in the documentation if it supersedes the project-wide interpreter chosen in Settings > Project > Python Interpreter for linter inspections. From my tests it currently doesn't but apparently it worked for the OP... Maybe by rebuilding the index and refreshing the background linter process.

Following up on @bad_coder 's attempt to fix that will be paraphrased as:

check the Run Configuration for pointing to a different python interpreter than the project level one

That fix worked for me:

  1. Bring up the Run [Context menu] | Edit Configurations

enter image description here

  1. Change the Python interpreter to the appropriate one: Shown below is a case where the interpreter is said to the earlier language level. Go to the dropdown and select a correct [python 3.8+] interpeter.

enter image description here

Related