Skip to content

fix: generate enum fields as str/int so raw values pass type checkers#725

Open
Alan4506 wants to merge 2 commits into
smithy-lang:developfrom
Alan4506:fix/enum-field-types
Open

fix: generate enum fields as str/int so raw values pass type checkers#725
Alan4506 wants to merge 2 commits into
smithy-lang:developfrom
Alan4506:fix/enum-field-types

Conversation

@Alan4506

@Alan4506 Alan4506 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description of changes:

When we generate a Python dataclass for a Smithy structure, each member that targets an enum shape gets a type annotation. Before #702, these fields were annotated as str | None (or int | None for intEnums), so users could pass either a raw string like "RETRIEVAL_MODE" or the enum constant ChatMode.RETRIEVAL_MODE: both worked and both passed type checkers.

#702 changed genericEnum in PythonSymbolProvider to return the enum class symbol directly, so those fields became ChatMode | None. This is more precise, but it means passing a raw string (awslabs/aws-sdk-python#54 for example) now fails static type checkers (e.g., ty) with errors like:

error[invalid-argument-type]: Argument is incorrect
  --> tests/integration/test_bidirectional_streaming.py:36:38
   |
36 |             value=ConfigurationEvent(chat_mode="RETRIEVAL_MODE")
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected `ChatMode | None`, found `Literal["RETRIEVAL_MODE"]`
   |

This PR restores the original str/int field typing while preserving all #702 functionality (error correction, unknown-value handling).

Testing:

Regenerated the qbusiness and connecthealth clients locally. Verfied their integration tests (awslabs/aws-sdk-python#54 and awslabs/aws-sdk-python#62) still passed, which means the #702 functionality is preserved. Type checker ty also passed with no issues.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Alan4506 Alan4506 requested a review from a team as a code owner June 24, 2026 04:03
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