Bug 2026703 - babel fails to build with Python 3.11: AttributeError: 'Translations' object has no attribute '_output_charset'
Summary: babel fails to build with Python 3.11: AttributeError: 'Translations' object ...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: babel
Version: 36
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: Tomáš Hrnčiar
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.11
TreeView+ depends on / blocked
 
Reported: 2021-11-25 14:23 UTC by Tomáš Hrnčiar
Modified: 2022-04-27 12:06 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-04-27 12:06:49 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github python-babel babel issues 819 0 None open babel fails to build with Python 3.11a2 AttributeError: 'Translations' object has no attribute '_output_charset' 2021-11-25 21:37:12 UTC
Github python-babel babel pull 835 0 None open Gettext deprecation fixes (for Python 3.11 compatibility) 2022-02-27 00:19:53 UTC

Description Tomáš Hrnčiar 2021-11-25 14:23:08 UTC
babel fails to build with Python 3.11.0a2.

=================================== FAILURES ===================================
_____________________ TranslationsTestCase.test_dnpgettext _____________________

self = <tests.test_support.TranslationsTestCase testMethod=test_dnpgettext>

    def test_dnpgettext(self):
        self.assertEqualTypeToo(
            'VohD1', self.translations.dngettext('messages1', 'foo1', 'foos1', 1))
        self.assertEqualTypeToo(
            'VohsD1', self.translations.dngettext('messages1', 'foo1', 'foos1', 2))
        self.assertEqualTypeToo(
>           'VohCTXD1', self.translations.dnpgettext('messages1', 'foo', 'foo1',
                                                     'foos1', 1))

tests/test_support.py:149: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
babel/support.py:508: in dnpgettext
    return self._domains.get(domain, self).npgettext(context, singular,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Translations: "PROJECT VERSION">, context = 'foo', singular = 'foo1'
plural = 'foos1', num = 1

    def npgettext(self, context, singular, plural, num):
        """Do a plural-forms lookup of a message id.  `singular` is used as the
        message id for purposes of lookup in the catalog, while `num` is used to
        determine which plural form to use.  The returned message string is an
        8-bit string encoded with the catalog's charset encoding, if known.
    
        If the message id for `context` is not found in the catalog, and a
        fallback is specified, the request is forwarded to the fallback's
        ``npgettext()`` method.  Otherwise, when ``num`` is 1 ``singular`` is
        returned, and ``plural`` is returned in all other cases.
        """
        ctxt_msg_id = self.CONTEXT_ENCODING % (context, singular)
        try:
            tmsg = self._catalog[(ctxt_msg_id, self.plural(num))]
>           if self._output_charset:
E           AttributeError: 'Translations' object has no attribute '_output_charset'

babel/support.py:412: AttributeError
_____________________ TranslationsTestCase.test_dpgettext ______________________

self = <tests.test_support.TranslationsTestCase testMethod=test_dpgettext>

    def test_dpgettext(self):
        self.assertEqualTypeToo(
            'VohD', self.translations.dgettext('messages1', 'foo'))
        self.assertEqualTypeToo(
>           'VohCTXD', self.translations.dpgettext('messages1', 'foo', 'foo'))

tests/test_support.py:128: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
babel/support.py:487: in dpgettext
    return self._domains.get(domain, self).pgettext(context, message)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Translations: "PROJECT VERSION">, context = 'foo', message = 'foo'

    def pgettext(self, context, message):
        """Look up the `context` and `message` id in the catalog and return the
        corresponding message string, as an 8-bit string encoded with the
        catalog's charset encoding, if known.  If there is no entry in the
        catalog for the `message` id and `context` , and a fallback has been
        set, the look up is forwarded to the fallback's ``pgettext()``
        method. Otherwise, the `message` id is returned.
        """
        ctxt_msg_id = self.CONTEXT_ENCODING % (context, message)
        missing = object()
        tmsg = self._catalog.get(ctxt_msg_id, missing)
        if tmsg is missing:
            if self._fallback:
                return self._fallback.pgettext(context, message)
            return message
        # Encode the Unicode tmsg back to an 8-bit string, if possible
>       if self._output_charset:
E       AttributeError: 'Translations' object has no attribute '_output_charset'

babel/support.py:376: AttributeError
_____________________ TranslationsTestCase.test_npgettext ______________________

self = <tests.test_support.TranslationsTestCase testMethod=test_npgettext>

    def test_npgettext(self):
        self.assertEqualTypeToo('Voh1',
                                self.translations.ngettext('foo1', 'foos1', 1))
        self.assertEqualTypeToo('Vohs1',
                                self.translations.ngettext('foo1', 'foos1', 2))
        self.assertEqualTypeToo('VohCTX1',
>                               self.translations.npgettext('foo', 'foo1',
                                                            'foos1', 1))

tests/test_support.py:93: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Translations: "PROJECT VERSION">, context = 'foo', singular = 'foo1'
plural = 'foos1', num = 1

    def npgettext(self, context, singular, plural, num):
        """Do a plural-forms lookup of a message id.  `singular` is used as the
        message id for purposes of lookup in the catalog, while `num` is used to
        determine which plural form to use.  The returned message string is an
        8-bit string encoded with the catalog's charset encoding, if known.
    
        If the message id for `context` is not found in the catalog, and a
        fallback is specified, the request is forwarded to the fallback's
        ``npgettext()`` method.  Otherwise, when ``num`` is 1 ``singular`` is
        returned, and ``plural`` is returned in all other cases.
        """
        ctxt_msg_id = self.CONTEXT_ENCODING % (context, singular)
        try:
            tmsg = self._catalog[(ctxt_msg_id, self.plural(num))]
>           if self._output_charset:
E           AttributeError: 'Translations' object has no attribute '_output_charset'

babel/support.py:412: AttributeError
______________________ TranslationsTestCase.test_pgettext ______________________

self = <tests.test_support.TranslationsTestCase testMethod=test_pgettext>

    def test_pgettext(self):
        self.assertEqualTypeToo('Voh', self.translations.gettext('foo'))
>       self.assertEqualTypeToo('VohCTX', self.translations.pgettext('foo',
                                                                     'foo'))

tests/test_support.py:73: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Translations: "PROJECT VERSION">, context = 'foo', message = 'foo'

    def pgettext(self, context, message):
        """Look up the `context` and `message` id in the catalog and return the
        corresponding message string, as an 8-bit string encoded with the
        catalog's charset encoding, if known.  If there is no entry in the
        catalog for the `message` id and `context` , and a fallback has been
        set, the look up is forwarded to the fallback's ``pgettext()``
        method. Otherwise, the `message` id is returned.
        """
        ctxt_msg_id = self.CONTEXT_ENCODING % (context, message)
        missing = object()
        tmsg = self._catalog.get(ctxt_msg_id, missing)
        if tmsg is missing:
            if self._fallback:
                return self._fallback.pgettext(context, message)
            return message
        # Encode the Unicode tmsg back to an 8-bit string, if possible
>       if self._output_charset:
E       AttributeError: 'Translations' object has no attribute '_output_charset'

babel/support.py:376: AttributeError
=============================== warnings summary ===============================
babel/messages/frontend.py:33
  /builddir/build/BUILD/Babel-2.9.1/babel/messages/frontend.py:33: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
    from distutils import log as distutils_log

babel/numbers.py::babel.numbers.format_number
babel/numbers.py::babel.numbers.format_number
babel/support.py::babel.support.Format.number
tests/test_numbers.py::test_format_number
tests/test_numbers.py::test_format_number
tests/test_support.py::test_format_number
  /builddir/build/BUILD/Babel-2.9.1/babel/numbers.py:352: DeprecationWarning: Use babel.numbers.format_decimal() instead.
    warnings.warn('Use babel.numbers.format_decimal() instead.', DeprecationWarning)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================== short test summary info ============================
FAILED tests/test_support.py::TranslationsTestCase::test_dnpgettext - Attribu...
FAILED tests/test_support.py::TranslationsTestCase::test_dpgettext - Attribut...
FAILED tests/test_support.py::TranslationsTestCase::test_npgettext - Attribut...
FAILED tests/test_support.py::TranslationsTestCase::test_pgettext - Attribute...
============ 4 failed, 3127 passed, 5 skipped, 7 warnings in 5.62s =============

The following deprecated functions and methods are removed in the gettext module: lgettext(), ldgettext(), lngettext() and ldngettext().

Function bind_textdomain_codeset(), methods output_charset() and set_output_charset(), and the codeset parameter of functions translation() and install() are also removed, since they are only used for the l*gettext() functions. (Contributed by Dong-hee Na and Serhiy Storchaka in bpo-44235.)

https://bugs.python.org/issue44235
https://docs.python.org/3.11/whatsnew/3.11.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.11/fedora-rawhide-x86_64/02986842-babel/

For all our attempts to build babel with Python 3.11, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/package/babel/

Testing and mass rebuild of packages is happening in copr. You can follow these instructions to test locally in mock if your package builds with Python 3.11:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/

Let us know here if you have any questions.

Python 3.11 is planned to be included in Fedora 37. To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.11.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires), so if this package is required a lot, it's important for us to get it fixed soon.
We'd appreciate help from the people who know this package best, but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Ben Cotton 2022-02-08 21:25:18 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle.
Changing version to 36.

Comment 2 Miro Hrončok 2022-02-27 00:19:53 UTC
I believe babel is needed for sphinx.

Let's test https://github.com/python-babel/babel/pull/835 ?

Comment 3 Felix Schwarz 2022-02-27 08:44:54 UTC
I'm aware of the upstream but I'm completely swamped right now. I believe python-sig can commit to babel so I'd be happy if someone else could add the PR + give some feedback upstream.

Comment 4 Tomáš Hrnčiar 2022-03-21 08:41:52 UTC
PR: https://src.fedoraproject.org/rpms/babel/pull-request/10

Comment 5 Tomáš Hrnčiar 2022-03-23 11:33:44 UTC
To prevent shipping babel from git snapshot, we won't merge it for now. If there is no release till Python 3.11 rebuilds we will ship it like this.

Comment 6 Petr Viktorin (pviktori) 2022-04-27 12:06:49 UTC
Babel was updated with an upstream fix.


Note You need to log in before you can comment on or make changes to this bug.