Skip to content

[python] Add Spector test for response-as-bool and fix ConstantType deserialization#10520

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-test-case-for-pull-4328
Draft

[python] Add Spector test for response-as-bool and fix ConstantType deserialization#10520
Copilot wants to merge 2 commits intomainfrom
copilot/add-test-case-for-pull-4328

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

Adds Python mock API test coverage for the azure/client-generator-core/response-as-bool Spector scenario (from Azure/typespec-azure#4328), which tests @responseAsBool — HEAD operations that return a bool based on HTTP status code (2xx → True, 404 → False).

Generator bug fix

The generator was emitting response.json() for ConstantType response types (Literal[True]/Literal[False]). HEAD responses have no body, so this caused a JSONDecodeError at runtime.

Before (generated code):

# response.json() fails — HEAD has no body
deserialized = _deserialize(Literal[True], response.json())

After (generated code):

# Directly assign the constant — no body parsing needed
deserialized = True

Fix is in builder_serializer.py: added a ConstantType branch in response_deserialization that emits the constant value directly instead of attempting body deserialization.

Changes

  • generator/pygen/codegen/serializers/builder_serializer.py — import ConstantType; add branch to emit constant value directly for ConstantType responses in DPG mode
  • package.json — bump @azure-tools/azure-http-specs to 0.1.0-alpha.40-dev.9 (first release containing the response-as-bool spec)
  • tests/mock_api/azure/test_azure_client_generator_core_response_as_bool.py — sync tests for exists()True and not_exists()False
  • tests/mock_api/azure/asynctests/test_azure_client_generator_core_response_as_bool_async.py — async counterpart

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Apr 27, 2026
Copilot AI changed the title [WIP] Add test case for pull request 4328 [python] Add Spector test for response-as-bool and fix ConstantType deserialization Apr 27, 2026
Copilot AI requested a review from msyyc April 27, 2026 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python] add test case for https://github.com/Azure/typespec-azure/pull/4328

2 participants