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

Fix error in python 3.11 with `typing` module evaluating a TypeVar eagerly #196

Closed AbstractUmbra closed 1 year ago

AbstractUmbra commented 1 year ago

The annotations of this file are eagerly evaluated rather than postponed causing an issue due to a CPython bug in 3.11.0

Rationale

Fixes an issue on 3.11+.

Summary of changes made

Forces the paginator_200.py file to use future annotations to prevent the following traceback:-

Traceback (most recent call last):
  File "C:\Users\Ava\Documents\Code\Mipha\bot.py", line 25, in <module>
    import jishaku
  File "C:\Users\Ava\AppData\Local\pypoetry\Cache\virtualenvs\mipha-EKccdFYI-py3.11\Lib\site-packages\jishaku\__init__.py", line 15, in <module>
    from jishaku.cog import *  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ava\AppData\Local\pypoetry\Cache\virtualenvs\mipha-EKccdFYI-py3.11\Lib\site-packages\jishaku\cog.py", line 20, in <module>
    from jishaku.features.filesystem import FilesystemFeature
  File "C:\Users\Ava\AppData\Local\pypoetry\Cache\virtualenvs\mipha-EKccdFYI-py3.11\Lib\site-packages\jishaku\features\filesystem.py", line 25, in <module>
    from jishaku.paginators import PaginatorInterface, WrappedFilePaginator, use_file_check
  File "C:\Users\Ava\AppData\Local\pypoetry\Cache\virtualenvs\mipha-EKccdFYI-py3.11\Lib\site-packages\jishaku\paginators.py", line 26, in <module>
    from jishaku.shim.paginator_200 import PaginatorEmbedInterface, PaginatorInterface
  File "C:\Users\Ava\AppData\Local\pypoetry\Cache\virtualenvs\mipha-EKccdFYI-py3.11\Lib\site-packages\jishaku\shim\paginator_200.py", line 29, in <module>
    a: MaybeButton[T],
       ~~~~~~~~~~~^^^
  File "C:\Users\Ava\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 360, in inner
    return cached(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ava\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 1391, in __getitem__
    new_args = self._determine_new_args(args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ava\AppData\Local\Programs\Python\Python311\Lib\typing.py", line 1439, in _determine_new_args
    subargs.append(new_arg_by_param[x])
                   ~~~~~~~~~~~~~~~~^^^
KeyError: +ClientT

Checklist

scarletcafe commented 1 year ago

Is there a known way to fix this without using __future__? I'd like to avoid having to opt into the lazy behavior, but I'll take it if nothing else works.

AbstractUmbra commented 1 year ago

Is there a known way to fix this without using __future__? I'd like to avoid having to opt into the lazy behavior, but I'll take it if nothing else works.

To the extent of my knowledge on the matter, not really. I don't believe you can wrap the annotation as a string directly, but I can try. (e.g. a: "MaybeButton[T]").

The other option is going from 3.11.0 -> 3.11.1 as it is (seemingly?) resolved in this version, but I cannot pinpoint the CPython commit/change that fixed it.

scarletcafe commented 1 year ago

Hard sell bumping right up until the latest patch version. I might have been able to do that in the old Jishaku days, but probably the best I could reasonably do today is pushing up to 3.10. I'll let the checks run and merge if there are no issues.

scarletcafe commented 1 year ago

Aaand it seems to break Sphinx. Cool stuff! This kind of stuff is sort of why I wanted to avoid it, I guess it might be fixable with a typing guard or something?

scarletcafe commented 1 year ago

I'll just figure it out on my end.

scarletcafe commented 1 year ago

Seems this fix doesn't actually cause the sphinx problems, some change on sphinx's side causing this.