Doesn't work with Python 3.11 due to removed gettext.bind_textdomain_codeset API
hedayat opened this issue · comments
Traceback (most recent call last):
File "/usr/bin/hamster", line 415, in <module>
i18n.setup_i18n()
File "/usr/lib/python3.11/site-packages/hamster/lib/i18n.py", line 24, in setup_i18n
module.bind_textdomain_codeset('hamster','utf8')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'gettext' has no attribute 'bind_textdomain_codeset'
The mentioned line is removed in Python 3.11 (or 3.10 in fact), and removing it from the code fixes the problem.
Monkey patch (restores compatibility with Python 3.11 / Fedora 37) :
try:
module.bind_textdomain_codeset('hamster','utf8')
except AttributeError:
pass
try:
module.bindtextdomaincodeset('hamster','utf8')
except AttributeError:
pass
monkeypatch applied but
xevilstar@ghost:~$ python3 --version
Python 3.11.1
xevilstar@ghost:~$ hamster version
Traceback (most recent call last):
File "/usr/bin/hamster", line 417, in <module>
usage = _(
^
NameError: name '_' is not defined
seems it misses to import gettext correctly ?
I think there's no point in keeping any "bind_textdomain_codeset" call at all. AFAIK gettext will return Unicode strings. The codeset is only relevant if you retrieve bytes out of the translation and I don't see why we would use functions that do that.
I have uploaded a fixed package in Debian unstable which switched to Python 3.11. It would be nice to have this fixed in git too (and maybe have a new release!).
I have uploaded a fixed package in Debian unstable which switched to Python 3.11
Can you just create a PR?
Can you just create a PR?
There's one already at #707 though you probably want to remove the line instead of commenting it out and update the explanation.