-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-130453: pygettext: Allow specifying multiple keywords with the same function name #131380
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
Changes from 2 commits
67c5cf7
63516d1
4426daf
9f8e9b1
ec02b07
4aa5151
2dcab79
a354d19
ab02d21
bac8b8d
a3d5d56
51b48f0
4daad1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -475,46 +475,46 @@ def _extract_docstring(self, node): | |||||
|
|
||||||
| def _extract_message(self, node): | ||||||
| func_name = self._get_func_name(node) | ||||||
| specs = self.options.keywords.get(func_name, []) | ||||||
| for spec in specs: | ||||||
| extracted = self._extract_message_with_spec(node, spec) | ||||||
| if extracted: | ||||||
| errors = [] | ||||||
| for spec in self.options.keywords.get(func_name, []): | ||||||
| err = self._extract_message_with_spec(node, spec) | ||||||
| if err is None: | ||||||
| break | ||||||
| errors.append(err) | ||||||
| else: | ||||||
| for err in errors: | ||||||
| print(err, file=sys.stderr) | ||||||
|
|
||||||
| def _extract_message_with_spec(self, node, spec): | ||||||
| """Extract a gettext call with the given spec. | ||||||
|
|
||||||
| Return True if the gettext call was successfully extracted, False | ||||||
| otherwise. | ||||||
| Return `None` if the gettext call was successfully extracted, | ||||||
tomasr8 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| otherwise return an error message. | ||||||
| """ | ||||||
| max_index = max(spec.values()) | ||||||
| has_var_positional = any(isinstance(arg, ast.Starred) for | ||||||
| arg in node.args[:max_index+1]) | ||||||
| if has_var_positional: | ||||||
| print(f'*** {self.filename}:{node.lineno}: Variable positional ' | ||||||
| f'arguments are not allowed in gettext calls', file=sys.stderr) | ||||||
| return False | ||||||
| return (f'*** {self.filename}:{node.lineno}: Variable positional ' | ||||||
| f'arguments are not allowed in gettext calls') | ||||||
|
||||||
| f'arguments are not allowed in gettext calls') | |
| f'arguments are not allowed in gettext calls') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error will still be printed multiple times.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With --keyword=_:1 --keyword=_:2, multiple errors will be printed for _(): "Expected at least 1 positional argument(s)...", "Expected at least 2 positional argument(s)...".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is misleading, since only one of arguments needs to be a string.