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

Fix parse test case on Python 3.12 #15577

Merged
merged 1 commit into from
Jul 12, 2023
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
6 changes: 6 additions & 0 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,12 @@ def visit_JoinedStr(self, n: ast3.JoinedStr) -> Expression:
# Don't make unnecessary join call if there is only one str to join
if len(strs_to_join.items) == 1:
return self.set_line(strs_to_join.items[0], n)
elif len(strs_to_join.items) > 1:
last = strs_to_join.items[-1]
if isinstance(last, StrExpr) and last.value == "":
# 3.12 can add an empty literal at the end. Delete it for consistency
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, why is that needed in CPython 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Interesting, why is that needed in CPython 🤔

It caused a crash over at flake8-bugbear too: PyCQA/flake8-bugbear#393

Copy link
Collaborator

Choose a reason for hiding this comment

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

If this has caused issues in two projects, should we report upstream?

Copy link
Member

Choose a reason for hiding this comment

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

Might be worth it, yeah

# between Python versions.
del strs_to_join.items[-1:]
join_method = MemberExpr(empty_string, "join")
join_method.set_line(empty_string)
result_expression = CallExpr(join_method, [strs_to_join], [ARG_POS], [None])
Expand Down