Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: newlines in literal strings example code results in invalid syntax #2569

Closed
1 of 4 tasks
eladb opened this issue Feb 14, 2021 · 1 comment · Fixed by #2571 or cdk8s-team/cdk8s-operator#228
Closed
1 of 4 tasks
Assignees
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. p0

Comments

@eladb
Copy link
Contributor

eladb commented Feb 14, 2021

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)

General Information

  • JSII Version: 1.20.1

What is the problem?

Consider the following jsii code:

/**
 * Hello world, this is cool.
 *
 * @example
 * const s1 = "\nFooBar";
 * const s2 = `Hello
 *   world!`;
 */
export class Hello {
  public sayHello() {
    return 'hello, world!';
  }
}

The generated python output looks like this:

class Hello(metaclass=jsii.JSIIMeta, jsii_type="python-repro.Hello"):
    """Hello world, this is cool.

    Example::

        # Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
        s1 = """
        FooBar"""
        s2 = """Hello
          world!"""
    """

    def __init__(self) -> None:
        jsii.create(Hello, self, [])

    @jsii.member(jsii_name="sayHello")
    def say_hello(self) -> builtins.str:
        return typing.cast(builtins.str, jsii.invoke(self, "sayHello", []))

Notice that the \n in the example code was converted to """ pairs which should be escaped or just left as is since they are part of a string literal.

This was introduced in #2419

@eladb eladb added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2021
mergify bot pushed a commit to aws/aws-cdk that referenced this issue Feb 14, 2021
Following up on #13036 with an additional instance in which rosetta fails to generate correct python code (aws/jsii#2569).

Fixes #13035


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@eladb eladb changed the title rosetta: newlines in literal strings example code results in invalid syntax python: newlines in literal strings example code results in invalid syntax Feb 14, 2021
eladb pushed a commit that referenced this issue Feb 14, 2021
…docstrings

Since docstrings are now rendered inside single-quoted multiline strings to allow the docstring itself to include example code with double-quoted multiline string literals. Those are the ones produced by rosetta for python.

Fixes #2569
@eladb eladb added the p0 label Feb 15, 2021
eladb pushed a commit that referenced this issue Feb 15, 2021
…docstrings (#2571)

Since docstrings are now rendered inside single-quoted multiline strings to allow the docstring itself to include example code with double-quoted multiline string literals. Those are the ones produced by rosetta for python.

Fixes #2569



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

NovakGu pushed a commit to NovakGu/aws-cdk that referenced this issue Feb 18, 2021
Following up on aws#13036 with an additional instance in which rosetta fails to generate correct python code (aws/jsii#2569).

Fixes aws#13035


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
mergify bot pushed a commit that referenced this issue Nov 17, 2021
Currently code examples in dotnet lose their indentation styles because we call `trim()` on each line in the code example. We want that behavior for other types of xml docs but not for code. This PR makes code a special case that calls `trimRight()` on each line, preserving the indentation on the left.

The only change in the snapshots is translating this example: 
```ts
docs const x = 12 + 44;
const s1 = "string";
const s2 = "string \nwith new newlines"; // see #2569
const s3 = `string
            with
            new lines`;
```

to this:
```
<code>int x = 12 + 44;
string s1 = "string";
string s2 = @"string
with new newlines"; // see #2569
string s3 = @"string
            with
            new lines";</code>
```

---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment