Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error when using a GUI library #449

Open
Almenon opened this issue Jun 24, 2023 · 1 comment
Open

Syntax error when using a GUI library #449

Almenon opened this issue Jun 24, 2023 · 1 comment
Labels
bug Something isn't working has-workaround

Comments

@Almenon
Copy link
Owner

Almenon commented Jun 24, 2023

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 Almenon added bug Something isn't working has-workaround labels Jun 24, 2023
@Almenon
Copy link
Owner Author

Almenon commented Jun 24, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has-workaround
Projects
None yet
Development

No branches or pull requests

1 participant