Skip to content

Deprecation warning for non-integer number in gettext is not always accurate #110519

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Bug report

gettext functions and methods that consider plural forms (like ngettext()) and directly or indirectly use GNUTranslations emit a deprecation warning if the number is not integer. But it only points to the line where GNUTranslations methods ngettext() or npgettext() are used directly. Since module level functions use it indirectly, and methods of other classes can use it indirectly as a fallback, the deprecation warning usually points to the line in the gettext module instead of the line in the user code that uses it. It makes deprecation warnings much less useful.

The following PR dynamically calculate the stacklevel for warning, skipping any gettext code.

Also I have found that many code is not covered by tests (in particular NullTranslations and domain-aware functions like dngettext()). The PR extends tests.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions