diff --git a/.chronus/changes/multi-namespace-doc-fix-2025-3-16-11-9-36.md b/.chronus/changes/multi-namespace-doc-fix-2025-3-16-11-9-36.md new file mode 100644 index 00000000000..3174ded7dd5 --- /dev/null +++ b/.chronus/changes/multi-namespace-doc-fix-2025-3-16-11-9-36.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Fix docstring type for multi namespaces \ No newline at end of file diff --git a/packages/http-client-python/generator/pygen/codegen/models/enum_type.py b/packages/http-client-python/generator/pygen/codegen/models/enum_type.py index 02c04c2db08..f32a0931b06 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/enum_type.py +++ b/packages/http-client-python/generator/pygen/codegen/models/enum_type.py @@ -52,7 +52,7 @@ def docstring_type(self, **kwargs: Any) -> str: """The python type used for RST syntax input and type annotation.""" type_annotation = self.value_type.type_annotation(**kwargs) - enum_type_annotation = f"{self.code_model.namespace}.models.{self.name}" + enum_type_annotation = f"{self.enum_type.client_namespace}.models.{self.name}" return f"{type_annotation} or ~{enum_type_annotation}" def get_json_template_representation( @@ -198,7 +198,7 @@ def docstring_type(self, **kwargs: Any) -> str: """The python type used for RST syntax input and type annotation.""" if self.code_model.options["models_mode"]: type_annotation = self.value_type.type_annotation(**kwargs) - enum_type_annotation = f"{self.code_model.namespace}.models.{self.name}" + enum_type_annotation = f"{self.client_namespace}.models.{self.name}" return f"{type_annotation} or ~{enum_type_annotation}" return self.value_type.type_annotation(**kwargs) diff --git a/packages/http-client-python/generator/pygen/codegen/models/model_type.py b/packages/http-client-python/generator/pygen/codegen/models/model_type.py index 9784bc7a5a2..3b0952c61a9 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/model_type.py +++ b/packages/http-client-python/generator/pygen/codegen/models/model_type.py @@ -292,7 +292,7 @@ def type_annotation(self, **kwargs: Any) -> str: def docstring_type(self, **kwargs: Any) -> str: type_annotation = self.type_annotation(need_model_alias=False, skip_quote=True, **kwargs) - return f"~{self.code_model.namespace}.models.{type_annotation}" + return f"~{self.client_namespace}.models.{type_annotation}" def docstring_text(self, **kwargs: Any) -> str: return self.name