Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel fails to build with Python 3.11a2 AttributeError: 'Translations' object has no attribute '_output_charset' #819

Closed
FelixSchwarz opened this issue Nov 25, 2021 · 1 comment · Fixed by #835
Assignees

Comments

@FelixSchwarz
Copy link
Contributor

initially filed by Tomáš Hrnčiar in rhbz #2026703:

    =================================== 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

@akx
Copy link
Member

akx commented Jan 28, 2022

Thanks for the heads-up!

This would be fixed by #835. Could you take a look, @FelixSchwarz?

@akx akx closed this as completed in #835 Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants