Skip to content

Commit

Permalink
Escape backslashes in docstring (#2560)
Browse files Browse the repository at this point in the history
  • Loading branch information
onlined authored Apr 30, 2024
1 parent 51ddf31 commit 7df1046
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def property_descriptions(self, async_mode: bool) -> List[str]:
":keyword int polling_interval: Default waiting time between two polls for LRO operations "
"if no Retry-After header is present."
)
retval = [s.replace("\\", "\\\\") for s in retval]
retval.append('"""')
return retval

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ def _documentation_string(
) -> List[str]:
retval: List[str] = []
sphinx_prefix = f":{description_keyword} {prop.client_name}:"
retval.append(
f"{sphinx_prefix} {prop.description(is_operation_file=False)}"
if prop.description(is_operation_file=False)
else sphinx_prefix
)
description = prop.description(is_operation_file=False).replace("\\", "\\\\")
retval.append(f"{sphinx_prefix} {description}" if description else sphinx_prefix)
retval.append(
f":{docstring_type_keyword} {prop.client_name}: {prop.type.docstring_type()}"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

class {{ enum.name }}({{ enum.value_type.type_annotation(is_operation_file=False) }}, Enum, metaclass=CaseInsensitiveEnumMeta):
{% if enum.yaml_data.get("description") %}
"""{{ enum.yaml_data["description"] | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
"""{{ op_tools.wrap_string(enum.yaml_data["description"], "\n ") }}
"""
{% endif %}

{% for value in enum.values %}
{{ value.name }} = {{ enum.value_type.get_declaration(value.value) }}
{% if value.description(is_operation_file=False) %}
"""{{ value.description(is_operation_file=False) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}"""
"""{{ op_tools.wrap_string(value.description(is_operation_file=False), "\n ") }}"""
{% endif %}
{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% import 'operation_tools.jinja2' as op_tools %}
# coding=utf-8
{{ code_model.options['license_header'] }}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% import 'operation_tools.jinja2' as op_tools %}
# coding=utf-8
# pylint: disable=too-many-lines
{{ code_model.options['license_header'] }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


{{ serializer.declare_model(model) }}
"""{{ model.description(is_operation_file=False) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
"""{{ op_tools.wrap_string(model.description(is_operation_file=False), "\n ") }}
{% if model.discriminated_subtypes %}

{{ serializer.discriminator_docstring(model) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
Expand Down Expand Up @@ -86,5 +86,5 @@
setattr(self.properties, key, value)
else:
super().__setattr__(key, value)
{% endif %}
{% endif %}
{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% set exist_constant = (model.properties | selectattr('constant') | first) is defined %}

{{ serializer.declare_model(model) }}
"""{{ model.description(is_operation_file=False) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
"""{{ op_tools.wrap_string(model.description(is_operation_file=False), "\n ") }}
{% if model.discriminated_subtypes %}

{{ serializer.discriminator_docstring(model) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro wrap_string(string, wrapstring, width=95) %}{{ string | wordwrap(width=width, break_long_words=False, break_on_hyphens=False, wrapstring=wrapstring)}}{% endmacro %}
{% macro wrap_string(string, wrapstring, width=95) %}{{ string | replace("\\", "\\\\") | wordwrap(width=width, break_long_words=False, break_on_hyphens=False, wrapstring=wrapstring)}}{% endmacro %}

{% macro description(builder, serializer) %}
{% set example_template = serializer.example_template(builder) %}
Expand Down

0 comments on commit 7df1046

Please sign in to comment.