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

errors parsing nested quotes #513

Open
rjwalters opened this issue May 3, 2024 · 4 comments
Open

errors parsing nested quotes #513

rjwalters opened this issue May 3, 2024 · 4 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Issue is not triaged.

Comments

@rjwalters
Copy link

I ran into the same problem reported in #419 this morning related to parsing nested double quotes in formatted strings like f"{"value"}".

It was especially confusing because I was able to format the file without any issue using commands in the vscode terminal:

% black --version
black, 24.4.2 (compiled: yes)
Python (CPython) 3.12.3
% black file.py

This sent me down a rabbit hole of trying to figure out how vscode was misconfigured.

I tried changing black-formatter.importStrategy to either fromEnvironment or useBundled but both settings resulted in the same error message...

2024-05-03 10:30:50.144 [info] error: cannot format (file.py): Cannot parse: f"{"value"}"

How can I check which version of black the extension uses?

@rjwalters rjwalters added the bug Issue identified by VS Code Team member as probable bug label May 3, 2024
@github-actions github-actions bot added the triage-needed Issue is not triaged. label May 3, 2024
@karthiknadig
Copy link
Member

@rjwalters In the logs Output > Black Formatter, it should have the exact version that is loaded by the extension.
image

@karthiknadig
Copy link
Member

@rjwalters When you run black from the command line, it might run black from different location than the one that the extension runs. This really depends on which python you have selected. because python -m black can be different depending on which python in running. The useBundled case will always run the bundled version and the version info there should be available in readme or in the extension welcome page from the extension view.

You can also force the extension to use the black binary that you have installed globally, by setting "black-formatter.path": ["black"]

@rjwalters
Copy link
Author

Okay here is what I see for each import strategy:

2024-05-03 10:00:15.229 [info] Global settings received on server:
{
    "cwd": "/",
    "workspace": "/",
    "args": [],
    "path": [],
    "interpreter": [],
    "importStrategy": "fromEnvironment",
    "showNotifications": "off"
}

2024-05-03 10:00:15.229 [info] sys.path used to run Server:
   /Users/rwalters/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/tool
   /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python312.zip
   /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12
   /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload
   /Users/rwalters/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/libs
2024-05-03 10:00:15.231 [info] /Users/rwalters/Documents/GitHub.nosync/python-robb/myenv/bin/python -m black --version
2024-05-03 10:00:15.231 [info] CWD formatter: /Users/rwalters/Documents/GitHub.nosync/python-robb
2024-05-03 10:00:15.275 [info] Version info for formatter running for /Users/rwalters/Documents/GitHub.nosync/python-robb:
black, 24.3.0 (compiled: no)
Python (CPython) 3.12.3

vs

2024-05-03 10:00:15.275 [info] SUPPORTED black>=22.3.0
FOUND black==24.3.0

2024-05-03 09:57:38.208 [info] Global settings received on server:
{
    "cwd": "/",
    "workspace": "/",
    "args": [],
    "path": [],
    "interpreter": [],
    "importStrategy": "useBundled",
    "showNotifications": "off"
}

2024-05-03 09:57:38.208 [info] sys.path used to run Server:
   /Users/rwalters/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/libs
   /Users/rwalters/.vscode/extensions/ms-python.black-formatter-2024.2.0/bundled/tool
   /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python312.zip
   /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12
   /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/lib-dynload
2024-05-03 09:57:38.210 [info] /Users/rwalters/Documents/GitHub.nosync/python-robb/myenv/bin/python -m black --version
2024-05-03 09:57:38.210 [info] CWD formatter: /Users/rwalters/Documents/GitHub.nosync/python-robb
2024-05-03 09:57:38.256 [info] Version info for formatter running for /Users/rwalters/Documents/GitHub.nosync/python-robb:
black, 24.3.0 (compiled: no)
Python (CPython) 3.12.3

2024-05-03 09:57:38.256 [info] SUPPORTED black>=22.3.0
FOUND black==24.3.0

It doesn't seem like importStrategy gets me to the same black version that gets used in the terminal...

I suppose this problem will go away when the extension updates the bundled black to 23.4.2+

@karthiknadig
Copy link
Member

@rjwalters This means that the python that is being used by extension is not the same python where you installed the terminal black.

With fromEnvironment the black being used is /Users/rwalters/Documents/GitHub.nosync/python-robb/myenv/bin/python -m black Try updating that version.

> /Users/rwalters/Documents/GitHub.nosync/python-robb/myenv/bin/python -m pip -U black

Then reload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Issue is not triaged.
Projects
None yet
Development

No branches or pull requests

2 participants