scarletcafe / jishaku

A debugging and testing cog for discord.py rewrite bots.
https://jishaku.readthedocs.io/en/latest/
MIT License
543 stars 182 forks source link

KeyError on Python version 3.11.0 #214

Closed tilda closed 1 year ago

tilda commented 1 year ago

Summary

When running a bot using Python 3.11, Jishaku fails to load with a cryptic KeyError: +ClientT stemming from the pagination code.

Reproduction steps

Able to reproduce this using Python 3.11.0 on Debian bullseye/11. Issue does not happen on Python 3.10.8 (same distro, machine, dependencies, etc)

Expected results

No errors from Jishaku/module should load successfully.

Actual results

Traceback:

[2023-10-15 21:43:20.038247] INFO: maho: also loading jishaku
Traceback (most recent call last):
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 935, in _load_from_module_spec
    spec.loader.exec_module(lib)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/jishaku/__init__.py", line 15, in <module>
    from jishaku.cog import *  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/jishaku/cog.py", line 20, in <module>
    from jishaku.features.filesystem import FilesystemFeature
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/jishaku/features/filesystem.py", line 25, in <module>
    from jishaku.paginators import PaginatorInterface, WrappedFilePaginator, use_file_check
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/jishaku/paginators.py", line 26, in <module>
    from jishaku.shim.paginator_200 import PaginatorEmbedInterface, PaginatorInterface
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/jishaku/shim/paginator_200.py", line 29, in <module>
    a: MaybeButton[T],
       ~~~~~~~~~~~^^^
  File "/home/tilda/.pyenv/versions/3.11.0/lib/python3.11/typing.py", line 360, in inner
    return cached(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/tilda/.pyenv/versions/3.11.0/lib/python3.11/typing.py", line 1391, in __getitem__
    new_args = self._determine_new_args(args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tilda/.pyenv/versions/3.11.0/lib/python3.11/typing.py", line 1439, in _determine_new_args
    subargs.append(new_arg_by_param[x])
                   ~~~~~~~~~~~~~~~~^^^
KeyError: +ClientT

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tilda/maho/bot.py", line 38, in <module>
    asyncio.run(setup_bot())
  File "/home/tilda/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/tilda/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tilda/.pyenv/versions/3.11.0/lib/python3.11/asyncio/base_events.py", line 650, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/tilda/maho/bot.py", line 33, in setup_bot
    await bot.load_extension('jishaku')
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 1013, in load_extension
    await self._load_from_module_spec(spec, name)
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 938, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'jishaku' raised an error: KeyError: +ClientT
Traceback (most recent call last):
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/logbook/handlers.py", line 238, in handle
    self.emit(record)
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/logbook/handlers.py", line 602, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/logbook/handlers.py", line 217, in format
    return self.formatter(record, self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/logbook/handlers.py", line 411, in __call__
    line = self.format_record(record, handler)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tilda/.local/share/virtualenvs/maho-RiUJz-OJ/lib/python3.11/site-packages/logbook/handlers.py", line 395, in format_record
    return self._formatter.format(record=record, handler=handler)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: sys.meta_path is None, Python is likely shutting down
Logged from file /home/tilda/.pyenv/versions/3.11.0/lib/python3.11/asyncio/base_events.py, line 1757

Checklist

System information

discord.py 2.3.2

Jishaku v2.5.1

scarletcafe commented 1 year ago

Could you try a newer version of 3.11? It sounds like this is a Python bug more than a Jishaku bug. 3.12 iirc doesn't work on the PyPI version judging by #213 , but master should work and I plan to do a release soon-ish hopefully

Soheab commented 1 year ago

We found out (in the dpy server) that this is indeed a bug in Python 3.11.0 and was fixed in 3.11.1

From the changelogs:

gh-98852: Fix subscription of type aliases containing bare generic types or types like TypeVar: for example tuple[A, T][int] and tuple[TypeVar, T][int], where A is a generic type, and T is a type variable.

tilda commented 1 year ago

yeah, seems 3.11.0 in particular is the issue. my pyenv was outdated so it thought .0 was the latest - update of that and a compile of a newer 3.11 release seemed to fix the issue.

since it's not actually that much of an issue i suppose i'll close this up...