Skip to content

Fix coverage gap in serialize_sequence_value continue statement#14933

Merged
tiangolo merged 3 commits intomodern-typesfrom
copilot/sub-pr-14932
Feb 17, 2026
Merged

Fix coverage gap in serialize_sequence_value continue statement#14933
tiangolo merged 3 commits intomodern-typesfrom
copilot/sub-pr-14932

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Line 316 in fastapi/_compat/v2.py was untested, causing coverage to fail at 99%. The line is a continue statement that skips NoneType when iterating union args in serialize_sequence_value.

Root Cause

Existing tests used list[str] | None, which orders union args as (list[str], NoneType). The loop processes list[str] first and breaks, never reaching the continue statement for NoneType.

Changes

  • Updated test_serialize_sequence_value_with_none_first_in_union to use explicit Union[None, list[str]] syntax
  • This places NoneType first in union args, exercising the continue statement before processing the list type
# Before: list[str] | None → union args are (list[str], NoneType)
field_info = FieldInfo(annotation=list[str] | None)

# After: Union[None, list[str]] → union args are (NoneType, list[str])  
field_info = FieldInfo(annotation=Union[None, list[str]])

Coverage now reaches 100%.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Updated test_serialize_sequence_value_with_none_first_in_union to use Union[None, list[str]]
instead of list[str] | None to ensure None appears first in union args, which properly tests
the continue statement at line 316 in fastapi/_compat/v2.py.

Co-authored-by: tiangolo <[email protected]>
Copilot AI changed the title [WIP] Update typing syntax for Python 3.10 Fix coverage gap in serialize_sequence_value continue statement Feb 17, 2026
Copilot AI requested a review from tiangolo February 17, 2026 08:46
@tiangolo tiangolo marked this pull request as ready for review February 17, 2026 09:36
@tiangolo tiangolo merged commit 0db6cc2 into modern-types Feb 17, 2026
17 of 19 checks passed
@tiangolo tiangolo deleted the copilot/sub-pr-14932 branch February 17, 2026 09:37
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 17, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing copilot/sub-pr-14932 (71c78a2) with modern-types (b2cee1d)

Open in CodSpeed

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.

2 participants