Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/http-client-python"
---

[Python] Fix duplicate `:keyword:`/`:paramtype:` lines in generated DPG model docstrings that duplicated the existing `:ivar:`/`:vartype:` entries
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ def input_documentation_string(prop: Property) -> list[str]:
# building the param line of the property doc
return _documentation_string(prop, "keyword", "paramtype")

def keyword_documentation_string(self, model: ModelType) -> list[str]:
# building the ``:keyword:``/``:paramtype:`` lines for the keyword-only
# arguments of the generated ``__init__`` overload so that the docstring
# keeps a 1:1 correlation with the keyword-only arguments in the signature.
retval: list[str] = []
for prop in sorted(self._init_line_parameters(model), key=lambda x: x.optional):
retval.extend(self.input_documentation_string(prop))
return retval

@staticmethod
def variable_documentation_string(prop: Property) -> list[str]:
return _documentation_string(prop, "ivar", "vartype")
Expand Down Expand Up @@ -428,6 +419,16 @@ def declare_model(self, model: ModelType) -> str:
basename += f", discriminator='{model.discriminator_value}'"
return f"class {model.name}({basename}):{self.class_pylint_disable(model)}"

def class_pylint_disable(self, model: ModelType) -> str:
retval = super().class_pylint_disable(model)
# DPG models render an empty ``@overload def __init__(self, *, ...)`` body, so the
# guideline checker validates the keyword-only arguments against the *class* docstring.
# We only document those arguments as instance variables (``:ivar:``) to avoid a redundant
# ``:keyword:`` entry per property, so silence the keyword/keyword-only correlation check.
if self._init_line_parameters(model):
retval = add_to_pylint_disable(retval, "docstring-keyword-should-match-keyword-only")
return retval

@staticmethod
def get_properties_to_declare(model: ModelType) -> list[Property]:
if model.parents:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
{% endfor %}
{% endfor %}
{% endif %}
{% if serializer.need_init(model) %}
{% for line in serializer.keyword_documentation_string(model) %}
{{ macros.wrap_model_string(line, '\n ') -}}
{% endfor %}
{% endif %}
"""

{% if model.is_polymorphic %}
Expand Down
Loading