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

Python 3.8: TypeError: 'type' object is not subscriptable #560

Closed
gptlang opened this issue Jan 28, 2024 · 11 comments
Closed

Python 3.8: TypeError: 'type' object is not subscriptable #560

gptlang opened this issue Jan 28, 2024 · 11 comments
Labels

Comments

@gptlang
Copy link

gptlang commented Jan 28, 2024

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/pynvim/plugin/host.py", line 193, in _load
    module = _handle_import(directory, name)
  File "/usr/local/lib/python3.8/dist-packages/pynvim/plugin/host.py", line 40, in _handle_import
    return importlib.import_module(name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
TypeError: 'type' object is not subscriptable

Reference: CopilotC-Nvim/CopilotChat.nvim#18

@justinmk
Copy link
Member

return importlib.import_module(name)

That seems like a bug in importlib? Does it work on later python versions?

@justinmk
Copy link
Member

Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pynvim/plugin/host.py", line 193, in _load
module = _handle_import(directory, name)

That seems like an out of date package. Maybe there are changes on master that weren't release yet. Here's line 193:

continue

@gptlang
Copy link
Author

gptlang commented Jan 29, 2024

That seems like a bug in importlib? Does it work on later python versions?

Yes. Works on later versions. I'm pretty sure importlib is standard library though; it shouldn't be out of date

@justinmk
Copy link
Member

I mean that your pynvim source is out of date compared to pynvim master (can you try that)?

@justinmk justinmk added the bug label Jan 29, 2024
@acheong08
Copy link

acheong08 commented Jan 30, 2024

pip install git+https://github.com/neovim/pynvim?

CC @Cassius0924

Edit: oops, wrong account

@Cassius0924
Copy link

git install git+https://github.com/neovim/pynvim?

CC @Cassius0924

Edit: oops, wrong account

It seems like there's a small mistake in your command. It's pip install not git install.

I used pip install git+https://github.com/neovim/pynvim to upgrade the pynvim version to 0.5.0.dev0, but there are still errors, but the error line has changed from line 193 to line 187

Encountered TypeError loading plugin at /root/.local/share/lunarvim/site/pack/lazy/opt/CopilotChat.nvim/rplugin/python3/utilities.py: 'type' object is not subscriptable
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/pynvim/plugin/host.py", line 187, in _load
    module = _handle_import(directory, name)
  File "/usr/local/lib/python3.8/dist-packages/pynvim/plugin/host.py", line 40, in _handle_import
    return importlib.import_module(name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
TypeError: 'type' object is not subscriptable

remote/host: python3 host registered plugins []
remote/host: generated rplugin manifest: /root/.local/share/lvim/rplugin.vim

@acheong08
Copy link

acheong08 commented Jan 30, 2024

It seems like there's a small mistake in your command. It's pip install not git install.

Yup. Typo

Could you try to reproduce this with a minimal Python file by importing importlib and calling it?

@Cassius0924
Copy link

Like below?

I wrote a Python file:

import importlib
import sys

sys.path.append(
    "/root/.local/share/lunarvim/site/pack/lazy/opt/CopilotChat.nvim/rplugin/python3"
)


def test_import(name):
    importlib.import_module(name)


test_import("copilot")

Still getting error after running:

Traceback (most recent call last):
  File "t_1.py", line 17, in <module>
    test_import("copilot")
  File "t_1.py", line 11, in test_import
    importlib.import_module(name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/root/.local/share/lunarvim/site/pack/lazy/opt/CopilotChat.nvim/rplugin/python3/copilot.py", line 10, in <module>
    import utilities
  File "/root/.local/share/lunarvim/site/pack/lazy/opt/CopilotChat.nvim/rplugin/python3/utilities.py", line 13, in <module>
    chat_history: list[typings.Message],
TypeError: 'type' object is not subscriptable

@Cassius0924
Copy link

This error seems not to be from pynvim, but from CopilotChat. I tried replacing list with List and it worked normally.

@gptlang
Copy link
Author

gptlang commented Jan 30, 2024

Ah I see. I suppose I got confused by the error output

@gptlang gptlang closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
@justinmk justinmk added question and removed bug labels Jan 30, 2024
@wookayin
Copy link
Member

wookayin commented Feb 4, 2024

Yes, the error was coming from the rplugin code, but the error message printed in Nvim can be confusing. We can improve error messages to clearly indicate that the SyntaxError/RuntimeError originates from the remote plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants