palantir / conjure-python

Conjure generator for Python clients
Apache License 2.0
19 stars 18 forks source link

Wrap indent docstring in newlines for UnionSnippet #777

Closed LorenzoMartini closed 7 months ago

LorenzoMartini commented 7 months ago

Before this PR

The UnionSnippet.emit(PythonPoetWriter poetWriter) method parses conjure class definitions into python code bindings. As part of the process, it extracts docs components from the apis and wraps them in the python docstring format, which is the triple-quote """.

If a docstring terminates with a " (which it shouldn't), that would cause a set of 4 consecutives ", which is invalid python and that will cause errors when reading from these files. For example, if I define my conjure api like

FaultyType:
  docs: this will say "ERROR"
  union:
    something: integer
    somethingElse: string

this will cause the following error when reading the generated conjure python bindings:

File "tmp.py", line 10
      """this will say "ERROR""""
                                                  ^
  SyntaxError: EOL while scanning string literal

After this PR

Fix up UnionSnippet to have newlines wrapping the content and extract the doc-writing into a separate method being reused across all cases.

==COMMIT_MSG== Wrap indent docstring in newlines for UnionSnippet ==COMMIT_MSG==

Possible downsides?

The pythonic way of doing docstrings has them in the format

"""Docstring
"""

but we currently do

"""
Docstring
"""

I will change that in a separate PR, this is a more time-sensitive fix.

changelog-app[bot] commented 7 months ago

Generate changelog in changelog-dir>`changelog/@unreleased`</changelog-dir

What do the change types mean? - `feature`: A new feature of the service. - `improvement`: An incremental improvement in the functionality or operation of the service. - `fix`: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way. - `break`: Has the potential to break consumers of this service's API, inclusive of both Palantir services and external consumers of the service's API (e.g. customer-written software or integrations). - `deprecation`: Advertises the intention to remove service functionality without any change to the operation of the service itself. - `manualTask`: Requires the possibility of manual intervention (running a script, eyeballing configuration, performing database surgery, ...) at the time of upgrade for it to succeed. - `migration`: A fully automatic upgrade migration task with no engineer input required. _Note: only one type should be chosen._
How are new versions calculated? - ❗The `break` and `manual task` changelog types will result in a major release! - 🐛 The `fix` changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease. - ✨ All others will result in a minor version release.

Type

- [ ] Feature - [x] Improvement - [ ] Fix - [ ] Break - [ ] Deprecation - [ ] Manual task - [ ] Migration

Description

Wrap indent docstring in newlines for UnionSnippet **Check the box to generate changelog(s)** - [x] Generate changelog entry
LorenzoMartini commented 7 months ago

Failing on unrelated stuff due to develop of this repo being broken

johnhany97 commented 7 months ago

Issue that's currently blocking this is fixed in https://github.com/palantir/conjure-python/pull/778

johnhany97 commented 7 months ago

👍

svc-autorelease commented 7 months ago

Released 4.10.0