mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Fix parse test case on Python 3.12

Open JukkaL opened this issue 2 years ago • 4 comments

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.

JukkaL avatar Jul 03 '23 17:07 JukkaL

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

github-actions[bot] avatar Jul 03 '23 17:07 github-actions[bot]

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

  • https://github.com/python/cpython/pull/106401

AlexWaygood avatar Jul 04 '23 10:07 AlexWaygood

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.

JukkaL avatar Jul 04 '23 14:07 JukkaL

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

AlexWaygood avatar Jul 04 '23 15:07 AlexWaygood

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.

JukkaL avatar Jul 12 '23 15:07 JukkaL

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!

AlexWaygood avatar Jul 12 '23 15:07 AlexWaygood