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

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Revert changes to parse_spec
  • Loading branch information
tomasr8 committed Feb 24, 2025
commit a3ef55bc629d77a0a673d94621d77dac61bb07b4
18 changes: 9 additions & 9 deletions Tools/i18n/pygettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,28 +352,28 @@ def parse_spec(spec):
raise ValueError(f'Invalid keyword spec {spec!r}: '
'argument positions must be strictly positive')

if pos in result:
if pos in result.values():
raise ValueError(f'Invalid keyword spec {spec!r}: '
'duplicate positions')

if is_context:
if 'msgctxt' in result.values():
if 'msgctxt' in result:
raise ValueError(f'Invalid keyword spec {spec!r}: '
'msgctxt can only appear once')
result[pos] = 'msgctxt'
elif 'msgid' not in result.values():
result[pos] = 'msgid'
elif 'msgid_plural' not in result.values():
result[pos] = 'msgid_plural'
result['msgctxt'] = pos
elif 'msgid' not in result:
result['msgid'] = pos
elif 'msgid_plural' not in result:
result['msgid_plural'] = pos
else:
raise ValueError(f'Invalid keyword spec {spec!r}: '
'too many positions')

if 'msgid' not in result.values() and 'msgctxt' in result.values():
if 'msgid' not in result and 'msgctxt' in result:
raise ValueError(f'Invalid keyword spec {spec!r}: '
'msgctxt cannot appear without msgid')

return name, result
return name, {v: k for k, v in result.items()}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be simpler to build result in that form from the beginning?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did that in d861c84, let me know if you like it better like that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It was just a question. I am fine with both variants.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I just wanted to let you see the difference :) I don't have a strong preference either, let's stick with the current version, then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually, I tried implementing some followup work on top of this PR (support for the t specifier, multiple keywords with the same funcname) and it's better to use the original representation because the diff in the followup PRs will be smaller.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So I did the right thing by letting the PR lie down for two days. πŸ˜„

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, good call πŸ™‚ And thanks for your super thorough reviews! It's really appreciated



@dataclass(frozen=True)
Expand Down