Skip to content

Conversation

@mardiros
Copy link
Contributor

@mardiros mardiros commented Oct 17, 2025

At the moment, the localization methods dpgettext and dnpgettext are not properly handled by extract command.

It raises KeyError exception.

except if you pass explicitly --keyword dpgettext:2c,3 --keyword dnpgettext:2c,3,4

This MR fixed the issue by declaring the default position parameter of those methods.

Traceback raised:

$ uv run pybabel extract -F tests/functionals/i18n/babel.ini --input-dirs tests/functionals/ -o tests/functionals/i18n/mydomain.pot
extracting messages from tests/functionals/i18n/test_l10n.py (encoding="utf-8")
Traceback (most recent call last):
  File "/home/guillaume/workspace/git/xcomponent/.venv/bin/pybabel", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/frontend.py", line 998, in main
    return CommandLineInterface().run(sys.argv)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/frontend.py", line 924, in run
    return cmdinst.run()
           ~~~~~~~~~~~^^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/frontend.py", line 522, in run
    for filename, lineno, message, comments, context in extracted:
                                                        ^^^^^^^^^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/extract.py", line 217, in extract_from_dir
    yield from check_and_call_extract_file(
    ...<8 lines>...
    )
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/extract.py", line 282, in check_and_call_extract_file
    for message_tuple in extract_from_file(
                         ~~~~~~~~~~~~~~~~~^
        method, filepath,
        ^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        strip_comment_tags=strip_comment_tags,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ):
    ^
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/extract.py", line 324, in extract_from_file
    return list(extract(method, fileobj, keywords, comment_tags,
                        options, strip_comment_tags))
  File "/home/guillaume/workspace/git/xcomponent/.venv/lib/python3.13/site-packages/babel/messages/extract.py", line 457, in extract
    specs = keywords[funcname] or None if funcname else None
            ~~~~~~~~^^^^^^^^^^
KeyError: 'dpgettext'

@akx akx force-pushed the features/extract-np-dnp branch from 7ab70cb to b3abc0b Compare December 29, 2025 11:55
@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.07%. Comparing base (e91c346) to head (b3abc0b).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1235   +/-   ##
=======================================
  Coverage   92.07%   92.07%           
=======================================
  Files          27       27           
  Lines        4692     4692           
=======================================
  Hits         4320     4320           
  Misses        372      372           
Flag Coverage Δ
macos-14-3.10 91.11% <ø> (ø)
macos-14-3.11 91.04% <ø> (ø)
macos-14-3.12 91.26% <ø> (ø)
macos-14-3.13 91.26% <ø> (ø)
macos-14-3.14 91.24% <ø> (ø)
macos-14-3.8 90.97% <ø> (ø)
macos-14-3.9 91.04% <ø> (ø)
macos-14-pypy3.10 91.11% <ø> (ø)
ubuntu-24.04-3.10 91.13% <ø> (ø)
ubuntu-24.04-3.11 91.06% <ø> (ø)
ubuntu-24.04-3.12 91.28% <ø> (ø)
ubuntu-24.04-3.13 91.28% <ø> (ø)
ubuntu-24.04-3.14 91.26% <ø> (ø)
ubuntu-24.04-3.8 91.00% <ø> (ø)
ubuntu-24.04-3.9 91.06% <ø> (ø)
ubuntu-24.04-pypy3.10 91.13% <ø> (ø)
windows-2022-3.10 91.12% <ø> (ø)
windows-2022-3.11 91.06% <ø> (ø)
windows-2022-3.12 91.27% <ø> (ø)
windows-2022-3.13 91.27% <ø> (ø)
windows-2022-3.14 91.25% <ø> (ø)
windows-2022-3.8 91.09% <ø> (ø)
windows-2022-3.9 91.05% <ø> (ø)
windows-2022-pypy3.10 91.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@akx akx left a comment

Choose a reason for hiding this comment

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

LGTM! I rebased this post #1241.

Thank you and happy holiday season!

@akx akx merged commit 12a14b6 into python-babel:master Dec 29, 2025
31 checks passed
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.

2 participants