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

Command 'Format Document With...' resulted in an error. TypeError: 'type' object is not subscriptable #564

Closed
BrikeX opened this issue Mar 6, 2025 · 4 comments
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Issue is not triaged.

Comments

@BrikeX
Copy link

BrikeX commented Mar 6, 2025

Diagnostic Data

  • Python version (& distribution if applicable, e.g., Anaconda): 3.8.20
  • Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): conda
  • Operating system (and version): Ubuntu 20.04.6 LTS x86_64
  • Version of tool extension you are using: 2025.2.0 on VSCode 1.98.0

Behaviour

Expected Behavior

Format documents correctly as before

Actual Behavior

I try to format this code
Image

by
Image

Image

, and then
Image

Reproduction Steps:

Do as what I have posted

Logs:

Click here for detailed logs 2025-03-06 13:30:06.780 [info] /home/x/miniconda3/envs/pp_thanos/bin/python -m black --stdin-filename /home/x/irepo/test.py - 2025-03-06 13:30:06.780 [info] CWD formatter: /home/x/irepo 2025-03-06 13:30:06.782 [info] [Error - 1:30:06 PM] Traceback (most recent call last): File "/home/x/.vscode/extensions/ms-python.black-formatter-2025.2.0/bundled/tool/lsp_server.py", line 531, in _run_tool_on_document result = utils.run_module( File "/home/x/.vscode/extensions/ms-python.black-formatter-2025.2.0/bundled/tool/lsp_utils.py", line 171, in run_module return _run_module(module, argv, use_stdin, source) File "/home/x/.vscode/extensions/ms-python.black-formatter-2025.2.0/bundled/tool/lsp_utils.py", line 156, in _run_module runpy.run_module(module, run_name="__main__") File "/home/x/miniconda3/envs/pp_thanos/lib/python3.8/runpy.py", line 203, in run_module mod_name, mod_spec, code = _get_module_details(mod_name) File "/home/x/miniconda3/envs/pp_thanos/lib/python3.8/runpy.py", line 144, in _get_module_details return _get_module_details(pkg_main_name, error) File "/home/x/miniconda3/envs/pp_thanos/lib/python3.8/runpy.py", line 111, in _get_module_details __import__(pkg_name) File "/home/x/.vscode/extensions/ms-python.black-formatter-2025.2.0/bundled/libs/black/__init__.py", line 32, in from black.cache import Cache File "/home/x/.vscode/extensions/ms-python.black-formatter-2025.2.0/bundled/libs/black/cache.py", line 16, in from black.mode import Mode File "/home/x/.vscode/extensions/ms-python.black-formatter-2025.2.0/bundled/libs/black/mode.py", line 67, in VERSION_TO_FEATURES: dict[TargetVersion, set[Feature]] = { TypeError: 'type' object is not subscriptable

2025-03-06 13:30:06.782 [info] [Error - 1:30:06 PM] Request textDocument/formatting failed.
2025-03-06 13:30:06.782 [info] Message: TypeError: 'type' object is not subscriptable
Code: -32603
[object Object]

Outcome When Attempting Debugging Steps:

Did running it from the command line work?
Using a command(black test.py) to format and it works fine
Image

Extra Details

  • What other Python-related extensions are you using?
  • autopep8 works fine but Black does not work
@BrikeX BrikeX added the bug Issue identified by VS Code Team member as probable bug label Mar 6, 2025
@github-actions github-actions bot added the triage-needed Issue is not triaged. label Mar 6, 2025
@vencoi
Copy link

vencoi commented Mar 6, 2025

I am experiencing the same issue with Docker Alpine 3.20 and Python 3.8.0. The formatter is not working as expected.

@vencoi
Copy link

vencoi commented Mar 6, 2025

Windows 11, Pyrhon 3.8.10

2025-03-06 17:32:22.478 [info] [Error - 5:32:22 PM] Traceback (most recent call last):
  File "c:\Users\vencoi\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\tool\lsp_server.py", line 531, in _run_tool_on_document
    result = utils.run_module(
  File "c:\Users\vencoi\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\tool\lsp_utils.py", line 171, in run_module
    return _run_module(module, argv, use_stdin, source)
  File "c:\Users\vencoi\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\tool\lsp_utils.py", line 156, in _run_module
    runpy.run_module(module, run_name="__main__")
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 203, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 144, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "c:\Users\vencoi\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\libs\black\__init__.py", line 32, in <module>
    from black.cache import Cache
  File "c:\Users\vencoi\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\libs\black\cache.py", line 16, in <module>
    from black.mode import Mode
  File "c:\Users\vencoi\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\libs\black\mode.py", line 67, in <module>
    VERSION_TO_FEATURES: dict[TargetVersion, set[Feature]] = {
TypeError: 'type' object is not subscriptable

2025-03-06 17:32:22.480 [info] [Trace - 5:32:22 PM] Received response 'textDocument/formatting - (8)' in 16ms. Request failed: TypeError: 'type' object is not subscriptable (-32603).
2025-03-06 17:32:22.480 [info] [Error - 5:32:22 PM] Request textDocument/formatting failed.
2025-03-06 17:32:22.480 [info]   Message: TypeError: 'type' object is not subscriptable
  Code: -32603 
[object Object]

@karthiknadig
Copy link
Member

Python 3.8 is deprecated in the latest version of black. I recommend pinning the extension to previous stable version. 2024.*

@BrikeX
Copy link
Author

BrikeX commented Mar 7, 2025

Python 3.8 is deprecated in the latest version of black. I recommend pinning the extension to previous stable version. 2024.*

OK, Version 2024.6.0 does work

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

3 participants