Skip to content

Commit

Permalink
Wrap indent docstring in newlines for UnionSnippet (#777) (#779)
Browse files Browse the repository at this point in the history
Wrap indent docstring in newlines for UnionSnippet
  • Loading branch information
LorenzoMartini authored Feb 7, 2024
1 parent d7d1222 commit 71b454c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 28 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-777.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Wrap indent docstring in newlines for UnionSnippet
links:
- https://github.com/palantir/conjure-python/pull/777
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ default String idForSorting() {
default void emit(PythonPoetWriter poetWriter) {
poetWriter.writeIndentedLine(String.format("class %s(ConjureBeanType):", className()));
poetWriter.increaseIndent();
docs().ifPresent(docs -> {
poetWriter.writeIndentedLine("\"\"\"");
poetWriter.writeIndentedLine(docs.get().trim());
poetWriter.writeIndentedLine("\"\"\"");
});
docs().ifPresent(poetWriter::writeDocs);

poetWriter.writeLine();

Expand Down Expand Up @@ -139,11 +135,7 @@ default void emit(PythonPoetWriter poetWriter) {

poetWriter.increaseIndent();
poetWriter.writeIndentedLine(String.format("# type: () -> %s", field.myPyType()));
field.docs().ifPresent(docs -> {
poetWriter.writeIndentedLine("\"\"\"");
poetWriter.writeIndentedLine(docs.get().trim());
poetWriter.writeIndentedLine("\"\"\"");
});
field.docs().ifPresent(poetWriter::writeDocs);
poetWriter.writeIndentedLine(String.format(
"return self._%s", PythonIdentifierSanitizer.sanitize(field.attributeName(), PROTECTED_FIELDS)));
poetWriter.decreaseIndent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ default void emit(PythonPoetWriter poetWriter) {
poetWriter.maintainingIndent(() -> {
poetWriter.writeIndentedLine(String.format("class %s(ConjureEnumType):", className()));
poetWriter.increaseIndent();
docs().ifPresent(docs -> {
poetWriter.writeIndentedLine("\"\"\"");
poetWriter.writeIndentedLine(docs.get().trim());
poetWriter.writeIndentedLine("\"\"\"");
});
docs().ifPresent(poetWriter::writeDocs);

poetWriter.writeLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ default void emit(PythonPoetWriter poetWriter) {
.map(PythonEndpointParam::myPyType)
.collect(Collectors.toList())),
myPyReturnType().orElse("None"));
docs().ifPresent(docs -> {
poetWriter.writeIndentedLine("\"\"\"");
poetWriter.writeIndentedLine(docs.get().trim());
poetWriter.writeIndentedLine("\"\"\"");
});
docs().ifPresent(poetWriter::writeDocs);

// replace "None" with "[]"
for (PythonEndpointParam param : paramsWithHeader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.base.Preconditions.checkState;

import com.google.errorprone.annotations.FormatMethod;
import com.palantir.conjure.spec.Documentation;
import java.io.PrintStream;

public final class PythonPoetWriter {
Expand Down Expand Up @@ -96,4 +97,11 @@ public PythonPoetWriter emit(Emittable emittable) {
emittable.emit(this);
return this;
}

public PythonPoetWriter writeDocs(Documentation docs) {
writeIndentedLine("\"\"\"");
writeIndentedLine(docs.get().trim());
writeIndentedLine("\"\"\"");
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ default void emit(PythonPoetWriter poetWriter) {
poetWriter.maintainingIndent(() -> {
poetWriter.writeIndentedLine(String.format("class %s(Service):", className()));
poetWriter.increaseIndent();
docs().ifPresent(docs -> {
poetWriter.writeIndentedLine("\"\"\"");
poetWriter.writeIndentedLine(docs.get().trim());
poetWriter.writeIndentedLine("\"\"\"");
});
docs().ifPresent(poetWriter::writeDocs);

endpointDefinitions().forEach(endpointDefinition -> {
poetWriter.writeLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ default void emit(PythonPoetWriter poetWriter) {
poetWriter.maintainingIndent(() -> {
poetWriter.writeIndentedLine(String.format("class %s(ConjureUnionType):", className()));
poetWriter.increaseIndent();
docs().ifPresent(docs -> poetWriter.writeIndentedLine(
String.format("\"\"\"%s\"\"\"", docs.get().trim())));
docs().ifPresent(poetWriter::writeDocs);

options()
.forEach(option -> poetWriter.writeIndentedLine(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71b454c

Please sign in to comment.