Skip to content

Commit 0f5d7b0

Browse files
Andrew Higginsbulldozer-bot[bot]
authored andcommitted
[fix] put docs on separate line from block comment marker (#138)
<!-- PR title should start with '[fix]', '[improvement]' or '[break]' if this PR would cause a patch, minor or major SemVer bump. Omit the prefix if this PR doesn't warrant a standalone release. --> ## Before this PR <!-- Describe the problem you encountered with the current state of the world (or link to an issue) and why it's important to fix now. --> Conjure documentation strings that happened to begin or end with a quote symbol (`"`) would break block comment escaping and cause the interpreter to fail. ```yml ... docs: These are the docs "this part is quoted" ... ``` renders in python as ```python """These are the docs "this part is quoted"""" ``` and the interpreter says: ```python SyntaxError: EOL while scanning string literal ``` ## After this PR <!-- Describe at a high-level why this approach is better. --> By putting the docstring on a separate line from the block comment markers we avoid this conflict. ```python """ These are the docs "this part is quoted" """ ``` <!-- Reference any existing GitHub issues, e.g. 'fixes #000' or 'relevant to #000' -->
1 parent a7a8eb1 commit 0f5d7b0

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

conjure-python-core/src/main/java/com/palantir/conjure/python/poet/PythonService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ default void emit(PythonPoetWriter poetWriter) {
5353
poetWriter.maintainingIndent(() -> {
5454
poetWriter.writeIndentedLine(String.format("class %s(Service):", className()));
5555
poetWriter.increaseIndent();
56-
docs().ifPresent(docs -> poetWriter.writeIndentedLine(String.format("\"\"\"%s\"\"\"", docs.get().trim())));
56+
docs().ifPresent(docs -> {
57+
poetWriter.writeIndentedLine("\"\"\"");
58+
poetWriter.writeIndentedLine(docs.get().trim());
59+
poetWriter.writeIndentedLine("\"\"\"");
60+
});
5761

5862
endpointDefinitions().forEach(endpointDefinition -> {
5963
poetWriter.writeLine();

conjure-python-core/src/test/resources/services/expected/package_name/another/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from typing import Any, Dict, Optional, Set
55

66
class TestService(Service):
7-
"""A Markdown description of the service."""
7+
"""
8+
A Markdown description of the service. "Might end with quotes"
9+
"""
810

911
def get_file_systems(self, auth_header):
1012
# type: (str) -> Dict[str, BackingFileSystem]

conjure-python-core/src/test/resources/types/example-service.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ services:
5050
default-auth: header
5151
base-path: /catalog
5252
docs: |
53-
A Markdown description of the service.
53+
A Markdown description of the service. "Might end with quotes"
5454
5555
endpoints:
5656
getFileSystems:

conjure-python-core/src/test/resources/types/expected/package_name/another/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from typing import Any, Dict, Optional, Set
55

66
class TestService(Service):
7-
"""A Markdown description of the service."""
7+
"""
8+
A Markdown description of the service. "Might end with quotes"
9+
"""
810

911
def get_file_systems(self, auth_header):
1012
# type: (str) -> Dict[str, BackingFileSystem]

0 commit comments

Comments
 (0)