Skip to content
Merged
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,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-python"
---

Fix initialize for model which only has discriminator property
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
__flattened_items = ["{{ model.flattened_items|join('\", \"') }}"]
{% endif %}

{% if not model.internal and serializer.init_line(model) %}
{% set need_init = (not model.internal) and (serializer.init_line(model) or model.discriminator)%}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For model which only has discriminator, we shall also generate __init__ otherwise initialization of model will report error.

{% if need_init %}
@overload
def __init__(
self,
Expand All @@ -64,7 +65,7 @@

{% endif %}
{% set initialize_properties = serializer.initialize_properties(model) %}
{% if not model.internal and serializer.init_line(model) or initialize_properties %}
{% if need_init or initialize_properties %}
def __init__(self, *args: Any, **kwargs: Any) -> None:{{ '# pylint: disable=useless-super-delegation' if not initialize_properties else '' }}
{% for line in serializer.super_call(model) %}
{{ line }}
Expand Down