Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-94194: gettext plural values must now be integers #94195

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

Closed
wants to merge 2 commits into from
Closed

gh-94194: gettext plural values must now be integers #94195

wants to merge 2 commits into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jun 24, 2022

Using non-integer value for selecting a plural form in gettext is
no longer supported. It never correctly worked and was deprecated
since Python 3.7.

Using non-integer value for selecting a plural form in gettext is
no longer supported.  It never correctly worked and was deprecated
since Python 3.7.
@vstinner vstinner marked this pull request as ready for review June 24, 2022 07:21
@vstinner
Copy link
Member Author

cc @JulienPalard @serhiy-storchaka

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worked on this issue, and it was more complex than just replacing warnings with exceptions. It is an interface with multiple implementations, so we perhaps need to add more warnings before making them errors.

Unfortunately I lost several hundreds of local branches and patches a week ago, so I have to start from beginning.

@vstinner
Copy link
Member Author

Unfortunately I lost several hundreds of local branches and patches a week ago, so I have to start from beginning.

Oh no :-( I'm very sorry for you 😔

@vstinner
Copy link
Member Author

I worked on this issue, and it was more complex than just replacing warnings with exceptions. It is an interface with multiple implementations, so we perhaps need to add more warnings before making them errors.

Ah? Would you mind to elaborate? Which function are you talking about? Do you want to deprecate more code paths?

@serhiy-storchaka
Copy link
Member

Currently only methods of GNUTranslations emit warnings. NullTranslations does not emit warnings. And global functions silently accept non-integer n if the translation for domain/language is not found. We should first add warnings in all these places, but only emit one warning per function call and with correct stacklevel. It is not easy because functions call other functions recursively.

@vstinner
Copy link
Member Author

Currently only methods of GNUTranslations emit warnings. NullTranslations does not emit warnings.

NullTranslations does "nothing". It doesn't parse the input file. I don't see the relationship with this issue which is only about removing deprecated code.

And global functions silently accept non-integer n if the translation for domain/language is not found.

Which global functions? I only found c2py() used by GNUTranslations._parse() to parse plural-forms.

@serhiy-storchaka
Copy link
Member

NullTranslations does "nothing".

It does not do "nothing". For example:

    def ngettext(self, msgid1, msgid2, n):
        if self._fallback:
            return self._fallback.ngettext(msgid1, msgid2, n)
        if n == 1:
            return msgid1
        else:
            return msgid2

It does choose msgid1 or msgid2, depending on the value of n. And it accepts float n.

Which global functions?

dngettext() and others.

@vstinner
Copy link
Member Author

This PR is about removing deprecated code in GNUTranslations.

So ok, there is a code path in NullTranslations that you would like to change. But it's not deprecated yet, and it's a different class.

Would you be ok to change GNUTranslations right now (this PR), and consider changing NullTranslations later? If yes, I will update the PR to clarify that the change is specific to GNUTranslations.

Note: I'm not convinced that NullTranslations needs to be changed, but I don't have a strong opinion about it.

@warsaw
Copy link
Member

warsaw commented Jun 29, 2022

This PR is about removing deprecated code in GNUTranslations.

Since GNUTranslations inherits from NullTranslations why not implement the checks in the base class and refactor as necessary to gain it in the base class (and potentially any other base classes) automatically? (Aside: I wish we had ABCs back when this module was originally written.)

FWIW, flufl.i18n implements a stack of translations for web-based applications (as opposed to single invocation CLIs) like Mailman which need multiple active translation contexts at any one time. NullTranslations serves as the default based translation context. I think ultimately it would be weird if you got an exception some times but not others depending on whether a context has been pushed on the stack.

@serhiy-storchaka
Copy link
Member

Would you be ok to change GNUTranslations right now (this PR), and consider changing NullTranslations later?

No. I would did it a year ago if it be so simple. See #88434.

Adding deprecations which cover all paths (including third-party implementations) and only produce one warning per call is a bit tricky.

@vstinner vstinner closed this Nov 4, 2022
@vstinner vstinner deleted the gettext_plural_int branch November 4, 2022 13:46
@vstinner
Copy link
Member Author

vstinner commented Nov 4, 2022

Sorry but I don't have the bandwidth to investigate on how to rework deeply gettext to handle the issue in every possible code path. My plan was only to change the few lines related to the current DeprecationWarning. If someone is more motivated than me, please go ahead. You can freely copy my code ;-) Get it as a patch. I just close my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants