Skip to content
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

Replace deprecated ast.Str with ast.Constant #1083

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
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
8 changes: 3 additions & 5 deletions babel/messages/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,11 @@ def _parse_python_string(value: str, encoding: str, future_flags: int) -> str |
)
if isinstance(code, ast.Expression):
body = code.body
if isinstance(body, ast.Str):
return body.s
if isinstance(body, ast.Constant):
return body.value
if isinstance(body, ast.JoinedStr): # f-string
if all(isinstance(node, ast.Str) for node in body.values):
return ''.join(node.s for node in body.values)
if all(isinstance(node, ast.Constant) for node in body.values):
return ''.join(str(node.value) for node in body.values)
return ''.join(node.value for node in body.values)
# TODO: we could raise an error or warning when not all nodes are constants
return None

Expand Down
Loading