I just upgraded Python to 3.10 for the new features, and when I do import sys; sys.version
using the IPython console in VS Code, it prints Python version 3.10.0. But when I open an editor window and try to enter a type annotation using |
for sum types, e.g. x:int|float
, Pylance highlights the |
and says "Alternative syntax for unions requires Python 3.10 or newer."
Any thoughts?
VS Code may be using a different version of python. Make sure that the default python interpreter (under settings, search for python) is python3.10 (if you are using linux, /usr/bin/python3.10 will probably work)
For me the solution was to use "python3" in "Default Interpreter Path". In my case, I noticed that terminal didn't recognize the command "python", but there was "python3" command, which comes with Python v3 and up. So I changed the path to that and I didn't get any errors anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With