Almenon / AREPL-vscode

Program python in real-time
MIT License
262 stars 31 forks source link

Syntax error when using a GUI library #449

Open Almenon opened 1 year ago

Almenon commented 1 year ago

Describe the bug When using a GUI library in the pyGuiLibraries setting, and the version of python/python3 in the terminal does not match what you ahve in VSCode, you can get a syntaxerror when no syntax error should appear.

To Reproduce Steps to reproduce the behavior:

  1. set python version to 3.11
  2. But have a earlier version of python be first in your PATH, so python/python3 is linked to a earlier version of python
  3. Run the below code twice
    import tkinter
    try:
    raise ExceptionGroup("eg",
        [ValueError(1), TypeError(2), OSError(3), OSError(4)])
    except* TypeError as e:
    print(f'caught {type(e)} with nested {e.exceptions}')
    except* OSError as e:
    print(f'caught {type(e)} with nested {e.exceptions}')

Expected behavior A clear and concise description of what you expected to happen. No syntax error. This is valid 3.11 syntax.

Additional context Error:

Command failed: python -m py_compile C:\Users\almenon\AppData\Local\Temp\pythonShellSyntaxCheck5067851224.py
Traceback (most recent call last):
  File "C:\Users\almenon\AppData\Local\Programs\Python\Python38-32\lib\py_compile.py", line 144, in compile
    code = loader.source_to_code(source_bytes, dfile or file,
  File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\almenon\AppData\Local\Temp\pythonShellSyntaxCheck5067851224.py", line 5
    except* TypeError as e:
          ^
SyntaxError: invalid syntax
Almenon commented 1 year ago

This is because this.PythonEvaluator.checkSyntax calls the static method PythonShell.checkSyntax, which uses the static variables defaultOptions.pythonPath or this.defaultPythonPath. These static variables can have a different python than what is set in the instance of the class.

I'll probably end up refactoring the code to avoid this issue in #439