You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Secrets Manager and Cognito Identity models have structure members with smithy.api#default": null. For example, in secrets-manager.json:
DeleteSecretRequest$RecoveryWindowInDays (target long), @default: null at line 614.
DeleteSecretRequest$ForceDeleteWithoutRecovery (target boolean), @default: null at line 621.
StructureGenerator.writeProperties only added the | None annotation for members with no @default trait, so these members resolved their default to None but kept the bare target annotation:
None is not assignable to int / bool, so pyright (run by PythonFormatter during codegen) fails the build:
src/aws_sdk_secretsmanager/models.py - error: Type "None" is not assignable to declared type "int" (reportAssignmentType)
src/aws_sdk_secretsmanager/models.py - error: Type "None" is not assignable to declared type "bool" (reportAssignmentType)
The fix
In the optional-members loop of StructureGenerator.writeProperties, mark the field nullable when the resolved default is a null node, so it is annotated | None:
if (!target.isDocumentShape()
&& member.expectTrait(DefaultTrait.class).toNode().isNullNode()) {
writer.putContext("nullable", true);
}
Document shapes are excluded. A document with a null default is a non-NoneDocument holding a null value, generated via default_factory as field(default_factory=lambda: Document(None)). Annotating it | None would be wrong.
Testing
Regenerated Secrets Manager and Cognito Identity: both build cleanly, and pyright reports 0 errors on the generated source.
Regenerated DynamoDB, SQS and all existing clients in aws-sdk-python repo (no @default: null members): generated source is unchanged.
:core:build (unit tests and the weather :core:integ integration test, whose model includes a Document = null member) passes.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
There is currently a Document member with a null default but that follows a different code path from what's being added here.
Thanks @arandito ! Addressed in 712e5a1. Added defaultNullBoolean and defaultNullLong to the integ model, matching the real cases we've seen so far. :core:integ passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Secrets Manager and Cognito Identity models have structure members with
smithy.api#default": null. For example, insecrets-manager.json:DeleteSecretRequest$RecoveryWindowInDays(targetlong),@default: nullat line 614.DeleteSecretRequest$ForceDeleteWithoutRecovery(targetboolean),@default: nullat line 621.StructureGenerator.writePropertiesonly added the| Noneannotation for members with no@defaulttrait, so these members resolved their default toNonebut kept the bare target annotation:Noneis not assignable toint/bool, so pyright (run byPythonFormatterduring codegen) fails the build:The fix
In the optional-members loop of
StructureGenerator.writeProperties, mark the field nullable when the resolved default is a null node, so it is annotated| None:This produces:
Document shapes are excluded. A document with a null default is a non-
NoneDocumentholding a null value, generated viadefault_factoryasfield(default_factory=lambda: Document(None)). Annotating it| Nonewould be wrong.Testing
@default: nullmembers): generated source is unchanged.:core:build(unit tests and the weather:core:integintegration test, whose model includes aDocument = nullmember) passes.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.