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

Fix parse test case on Python 3.12 #15577

merged 1 commit into from
Jul 12, 2023

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 3, 2023

This fixes the test case testFStringWithFormatSpecifierExpression on Python 3.12.

Strip redundant empty string literal from AST generated from f-string. It's not generated on earlier Python versions and it seems fine to just drop it.

This fixes the test case testFStringWithFormatSpecifierExpression on Python 3.12.

Strip redundant empty string literal from AST generated from f-string. It's
not generated on earlier Python versions and it seems fine to just drop it.
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

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2023

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@AlexWaygood
Copy link
Member

Looks like this might be changed in CPython, so maybe we should just wait for the next 3.12 beta rather than merging this:

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 4, 2023

maybe we should just wait for the next 3.12 beta rather than merging this

We can wait until the next beta, unless perhaps we want to enable 3.12 in CI before the next beta is available. I'll keep this open for now.

@AlexWaygood
Copy link
Member

AlexWaygood commented Jul 4, 2023

unless perhaps we want to enable 3.12 in CI before the next beta is available.

For now could we maybe just skip the test? I can't remember the pytest equivalent off the top of my head, but for unittest I'd just decorate the test with:

@skipIf(
    sys.version_info[:4] == (3, 12, 0, "beta") and sys.version_info[4] < 4,
    "Early 3.12 betas had a bug"
)

Though mypy's test suite is very data-driven I guess, so maybe it's more difficult to be that granular for a single test case

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 12, 2023

This is still failing for me on Python 3.12.0 beta 4. I'm leaning towards merging this. We can always revert this afterwards if it's no longer needed.

@AlexWaygood
Copy link
Member

This is still failing for me on Python 3.12.0 beta 4. I'm leaning towards merging this. We can always revert this afterwards if it's no longer needed.

Makes sense!

@JukkaL JukkaL merged commit 235a3bb into master Jul 12, 2023
18 checks passed
@JukkaL JukkaL deleted the fix-3.12-parse-test branch July 12, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants