Skip to content

Commit 9dd74be

Browse files
doc(Python): Document TODO to refactor string conversion (#587)
1 parent dcc45dc commit 9dd74be

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/awssdk/shapevisitor/AwsSdkToDafnyShapeVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ public String stringShape(StringShape shape) {
207207
}
208208

209209
// Convert native Python string to Dafny Seq of UTF-16 characters
210+
// TODO: This is a long conversion that is used often in generated code, since this is written for *all* strings.
211+
// This should be refactored into the conversionwriter package.
210212
return "Seq(''.join([chr(int.from_bytes(pair, 'big')) for pair in zip(*[iter(%1$s.encode('utf-16-be'))]*2)]))".formatted(
211213
dataSource
212214
);

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/awssdk/shapevisitor/DafnyToAwsSdkShapeVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ public String stringShape(StringShape shape) {
194194
return enumShape(EnumShape.fromStringShape(shape).get());
195195
}
196196
// Convert Dafny Seq of UTF-16 characters to native Python string
197+
// TODO: This is a long conversion that is used often in generated code, since this is written for *all* strings.
198+
// This should be refactored into the conversionwriter package.
197199
return "b''.join(ord(c).to_bytes(2, 'big') for c in %1$s).decode('utf-16-be')".formatted(
198200
dataSource
199201
);

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/shapevisitor/DafnyToLocalServiceShapeVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ public String stringShape(StringShape shape) {
244244
return "bytes(%1$s.Elements).decode('utf-8')".formatted(dataSource);
245245
}
246246
// Convert Dafny Seq of UTF-16 characters to native Python string
247+
// TODO: This is a long conversion that is used often in generated code, since this is written for *all* strings.
248+
// This should be refactored into the conversionwriter package.
247249
return "b''.join(ord(c).to_bytes(2, 'big') for c in %1$s).decode('utf-16-be')".formatted(
248250
dataSource
249251
);

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithypython/localservice/shapevisitor/LocalServiceToDafnyShapeVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ public String stringShape(StringShape shape) {
246246
return "Seq(%1$s.encode('utf-8'))".formatted(dataSource);
247247
}
248248
// Convert native Python string to Dafny Seq of UTF-16 characters
249+
// TODO: This is a long conversion that is used often in generated code, since this is written for *all* strings.
250+
// This should be refactored into the conversionwriter package.
249251
return "Seq(''.join([chr(int.from_bytes(pair, 'big')) for pair in zip(*[iter(%1$s.encode('utf-16-be'))]*2)]))".formatted(
250252
dataSource
251253
);

0 commit comments

Comments
 (0)