Skip to content

Add test coverage for Python 3.12+ type params and PEP 701 f-strings#5245

Open
Emilianocarfu88 wants to merge 1 commit into
psf:mainfrom
Emilianocarfu88:tests/py312-type-params-fstrings
Open

Add test coverage for Python 3.12+ type params and PEP 701 f-strings#5245
Emilianocarfu88 wants to merge 1 commit into
psf:mainfrom
Emilianocarfu88:tests/py312-type-params-fstrings

Conversation

@Emilianocarfu88

Copy link
Copy Markdown

Description

Adds test coverage for Python 3.12+ syntax that was thin in the suite, focused on how
PEP 695 type parameters (incl. PEP 696 defaults, *TypeVarTuple/**ParamSpec) and
PEP 701 f-strings interact with Black's line splitting and comment handling.

New data-driven cases (auto-discovered by test_simple_format, so each also runs Black's
built-in AST-equivalence, idempotency/stability, preview, and line-length-1 checks):

  • tests/data/cases/type_params_comments.py — comments inside type-param brackets
    (inline, leading/standalone, on bounds and constraint tuples).
  • tests/data/cases/type_param_defaults_comments.py — PEP 696 defaults with comments and
    wrapping.
  • tests/data/cases/fstring_pep701_comments.py — comments in multiline interpolations,
    nested/quote-reuse f-strings, format specs, = debug, call-argument splitting.
  • tests/data/cases/type_params_line_split.py — overflowing type-param lists,
    bounds/constraints, combined type-param + argument + return-type splitting.

Property-based tests:

  • tests/test_pep695_701_properties.py — targeted Hypothesis strategies for type-param
    lists and f-strings asserting idempotency (assert_stable) and AST safety
    (assert_equivalent) across varied modes (line lengths incl. 1, preview, magic-comma,
    string normalization). Every generated example is compile()-checked first so a
    strategy bug can't masquerade as a Black bug. Mirrors the deterministic settings of
    scripts/fuzz.py.

Regression test:

All expected # output blocks were generated by running Black itself, never hand-written.

Checklist

  • Added tests
  • No user-facing changes, so no CHANGES.md entry (happy to add one if preferred)

Relates to #5243.

Cover gaps around PEP 695 type parameters (incl. PEP 696 defaults),
*TypeVarTuple/**ParamSpec, and PEP 701 f-strings, focusing on their
interaction with line splitting and comment handling.

- tests/data/cases/type_params_comments.py: comments inside type-param
  brackets (inline, leading/standalone, on bounds and constraint tuples)
- tests/data/cases/type_param_defaults_comments.py: PEP 696 defaults with
  comments and wrapping
- tests/data/cases/fstring_pep701_comments.py: comments in multiline
  interpolations, nested/quote-reuse f-strings, format specs, = debug,
  call-argument splitting
- tests/data/cases/type_params_line_split.py: overflowing type-param lists,
  bounds/constraints, combined type-param + argument + return-type splitting
- tests/test_pep695_701_properties.py: Hypothesis strategies for type-param
  lists and f-strings asserting idempotency (assert_stable) and AST safety
  (assert_equivalent) across varied modes
- tests/test_regression_type_params.py: strict-xfail pinning psf#5243
  (magic trailing comma fails to explode a type-param list containing
  *TypeVarTuple/**ParamSpec)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant