Make it work with Python 3.12
Scenario
The current version can't work with Python 3.12 for two reasons:
- The
gettext.translationfunction signature has changed and thus use theclass_parameter instead ofcodeset; - The
locale.formatthat was deprecated since 3.7 has been dropped and now we should uselocale.format_string.
@gcavalcante8808 Thank you for your contribution.
I am a bit hesitant to merge this, because the tests didn't run. It is caused by old test configuration and the fact that Travis has duped open-source support.
I would like to see, that the code is running in the new Python as well as the older versions.
Would you be able to rewrite .travis.yml into GitHub actions configuration and update the Python stack to the currently supported versions?
got this error in python 3.12.1
% python -m unittest discover
EEEE
======================================================================
ERROR: tests.test_api (unittest.loader._FailedTest.tests.test_api)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_api
Traceback (most recent call last):
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/loader.py", line 394, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/loader.py", line 337, in _get_module_from_name
__import__(name)
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/tests/test_api.py", line 8, in <module>
from InvoiceGenerator.api import Address, Client, Creator, Invoice, \
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/api.py", line 7, in <module>
from InvoiceGenerator.conf import _
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/conf.py", line 30, in <module>
_ = get_gettext(lang)
^^^^^^^^^^^^^^^^^
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/conf.py", line 13, in get_gettext
t = gettext.translation(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/gettext.py", line 538, in translation
t = _translations.setdefault(key, class_(fp))
^^^^^^^^^^
TypeError: 'str' object is not callable
======================================================================
ERROR: tests.test_generator (unittest.loader._FailedTest.tests.test_generator)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_generator
Traceback (most recent call last):
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/loader.py", line 394, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/loader.py", line 337, in _get_module_from_name
__import__(name)
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/tests/test_generator.py", line 5, in <module>
from InvoiceGenerator.api import Client, Creator, Invoice, Item, Provider
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/api.py", line 7, in <module>
from InvoiceGenerator.conf import _
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/conf.py", line 30, in <module>
_ = get_gettext(lang)
^^^^^^^^^^^^^^^^^
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/conf.py", line 13, in get_gettext
t = gettext.translation(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/gettext.py", line 538, in translation
t = _translations.setdefault(key, class_(fp))
^^^^^^^^^^
TypeError: 'str' object is not callable
======================================================================
ERROR: tests.test_pdf (unittest.loader._FailedTest.tests.test_pdf)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_pdf
Traceback (most recent call last):
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/loader.py", line 394, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/loader.py", line 337, in _get_module_from_name
__import__(name)
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/tests/test_pdf.py", line 7, in <module>
from InvoiceGenerator.api import Client, Creator, Invoice, Item, Provider
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/api.py", line 7, in <module>
from InvoiceGenerator.conf import _
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/conf.py", line 30, in <module>
_ = get_gettext(lang)
^^^^^^^^^^^^^^^^^
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/conf.py", line 13, in get_gettext
t = gettext.translation(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/gettext.py", line 538, in translation
t = _translations.setdefault(key, class_(fp))
^^^^^^^^^^
TypeError: 'str' object is not callable
======================================================================
ERROR: tests.test_pohoda (unittest.loader._FailedTest.tests.test_pohoda)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_pohoda
Traceback (most recent call last):
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/loader.py", line 394, in _find_test_path
module = self._get_module_from_name(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/loader.py", line 337, in _get_module_from_name
__import__(name)
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/tests/test_pohoda.py", line 6, in <module>
from InvoiceGenerator.api import Client, Creator, Invoice, Item, Provider
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/api.py", line 7, in <module>
from InvoiceGenerator.conf import _
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/conf.py", line 30, in <module>
_ = get_gettext(lang)
^^^^^^^^^^^^^^^^^
File "/Users/bandaralruwaili/Downloads/InvoiceGenerator-update-python3.12_changes/InvoiceGenerator/conf.py", line 13, in get_gettext
t = gettext.translation(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.12.1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/gettext.py", line 538, in translation
t = _translations.setdefault(key, class_(fp))
^^^^^^^^^^
TypeError: 'str' object is not callable
----------------------------------------------------------------------
Ran 4 tests in 0.001s
FAILED (errors=4)
I definitely had to address both of these issues.
Bullet point . 1 I have addressed by writing class_=None or simply commenting out that parameter, both methods work.
I have tried the original class_= 'utf8' and got the same error as @BandarHL
Bullet point 2. Definitely needs to be committed for Python 3.12 and above.
Scenario
The current version can't work with Python 3.12 for two reasons:
1. The `gettext.translation` function signature has changed and thus use the `class_` parameter instead of `codeset`; 2. The `locale.format` that was deprecated since 3.7 has been dropped and now we should use `locale.format_string`.
Can this be closed after merging of #53?
Can this be closed after merging of #53?
Yeah. Both changes were associated with deprecated gettext code that got dropped on python 3.7.
OK, I am closing this.