From 27e9c46a82c8a7a76c599b9c766c657a3c37537b Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Sat, 9 Nov 2024 11:26:36 +0300 Subject: [PATCH 01/11] concatenate base class and implemented interfaces --- .../Writers/Python/CodeClassDeclarationWriter.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs b/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs index 765dc76942..abcf7d2327 100644 --- a/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs @@ -36,11 +36,12 @@ public override void WriteCodeElement(ClassDeclaration codeElement, LanguageWrit } var abcClass = !codeElement.Implements.Any() ? string.Empty : $"{codeElement.Implements.Select(static x => x.Name).Aggregate((x, y) => x + ", " + y)}"; - var derivation = codeElement.Inherits is CodeType inheritType && + var baseClass = codeElement.Inherits is CodeType inheritType && conventions.GetTypeString(inheritType, codeElement) is string inheritSymbol && !string.IsNullOrEmpty(inheritSymbol) ? inheritSymbol : - abcClass; + string.Empty; + var derivation = string.IsNullOrEmpty(baseClass) ? abcClass : string.IsNullOrEmpty(abcClass) ? baseClass : $"{baseClass}, {abcClass}"; writer.WriteLine($"class {codeElement.Name}({derivation}):"); writer.IncreaseIndent(); if (codeElement.Parent is CodeClass parent) From 704fdeb50a90d2abb1563e545e4f1cf085f951e2 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Sat, 9 Nov 2024 11:29:13 +0300 Subject: [PATCH 02/11] reove python suprresion --- it/config.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/it/config.json b/it/config.json index 1e7120f803..a7006eeded 100644 --- a/it/config.json +++ b/it/config.json @@ -242,10 +242,6 @@ { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/2484" - }, - { - "Language": "python", - "Rationale": "https://github.com/microsoft/kiota/issues/5637" } ] }, @@ -262,4 +258,4 @@ "Suppressions": [], "IdempotencySuppressions": [] } -} +} \ No newline at end of file From c2ad01db22e6a9a695188bac26b3aecfaee1f118 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Sat, 9 Nov 2024 11:41:42 +0300 Subject: [PATCH 03/11] remove quotes around all returned types --- src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs index 3b391cdb8f..efac9434d8 100644 --- a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs @@ -809,10 +809,11 @@ private string GetSerializationMethodName(CodeTypeBase propType) _ => "write_object_value", }; } + internal string GetTypeFactory(bool isVoid, bool isStream, bool isEnum, string returnType) { if (isVoid) return string.Empty; - if (isStream || isEnum) return $" \"{returnType}\","; + if (isStream || isEnum) return $" {returnType},"; if (conventions.IsPrimitiveType(returnType)) return $" {returnType},"; return $" {returnType},"; } From b33eb7ee82881c5d690ef464cfbc238d7cf2e7a0 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Sat, 9 Nov 2024 11:47:21 +0300 Subject: [PATCH 04/11] remove quotes around primitive type definitions --- src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs index efac9434d8..3b391cdb8f 100644 --- a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs @@ -809,11 +809,10 @@ private string GetSerializationMethodName(CodeTypeBase propType) _ => "write_object_value", }; } - internal string GetTypeFactory(bool isVoid, bool isStream, bool isEnum, string returnType) { if (isVoid) return string.Empty; - if (isStream || isEnum) return $" {returnType},"; + if (isStream || isEnum) return $" \"{returnType}\","; if (conventions.IsPrimitiveType(returnType)) return $" {returnType},"; return $" {returnType},"; } From 77bedc12e1a1b24ad01500f4136775e85854bd8e Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Sat, 9 Nov 2024 12:42:02 +0300 Subject: [PATCH 05/11] fix code complexty --- .../Writers/Python/CodeClassDeclarationWriter.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs b/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs index abcf7d2327..4f4c8b2fcf 100644 --- a/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs @@ -41,7 +41,19 @@ public override void WriteCodeElement(ClassDeclaration codeElement, LanguageWrit !string.IsNullOrEmpty(inheritSymbol) ? inheritSymbol : string.Empty; - var derivation = string.IsNullOrEmpty(baseClass) ? abcClass : string.IsNullOrEmpty(abcClass) ? baseClass : $"{baseClass}, {abcClass}"; + var derivation = string.Empty; + if (string.IsNullOrEmpty(baseClass)) + { + derivation = abcClass; + } + else if (string.IsNullOrEmpty(abcClass)) + { + derivation = baseClass; + } + else + { + derivation = $"{baseClass}, {abcClass}"; + } writer.WriteLine($"class {codeElement.Name}({derivation}):"); writer.IncreaseIndent(); if (codeElement.Parent is CodeClass parent) From 99b113ce9a195506b86d5a0a65af3a7e07b2be7a Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Sat, 9 Nov 2024 12:50:05 +0300 Subject: [PATCH 06/11] simplify method --- .../Python/CodeClassDeclarationWriter.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs b/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs index 4f4c8b2fcf..89aec8f6dd 100644 --- a/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs @@ -22,7 +22,16 @@ public override void WriteCodeElement(ClassDeclaration codeElement, LanguageWrit _codeUsingWriter.WriteConditionalInternalImports(codeElement, writer, parentNamespace); } + WriteParentClassImportsAndDecorators(codeElement, writer); + var derivation = GetDerivation(codeElement); + writer.WriteLine($"class {codeElement.Name}({derivation}):"); + writer.IncreaseIndent(); + WriteInnerClassImportsAndDescriptions(codeElement, writer, parentNamespace); + } + + private void WriteParentClassImportsAndDecorators(ClassDeclaration codeElement, LanguageWriter writer) + { if (codeElement.Parent is CodeClass parentClass) { if (codeElement.Inherits != null) @@ -34,28 +43,32 @@ public override void WriteCodeElement(ClassDeclaration codeElement, LanguageWrit writer.WriteLine("@dataclass"); } } + } + private string GetDerivation(ClassDeclaration codeElement) + { var abcClass = !codeElement.Implements.Any() ? string.Empty : $"{codeElement.Implements.Select(static x => x.Name).Aggregate((x, y) => x + ", " + y)}"; var baseClass = codeElement.Inherits is CodeType inheritType && conventions.GetTypeString(inheritType, codeElement) is string inheritSymbol && !string.IsNullOrEmpty(inheritSymbol) ? inheritSymbol : string.Empty; - var derivation = string.Empty; if (string.IsNullOrEmpty(baseClass)) { - derivation = abcClass; + return abcClass; } else if (string.IsNullOrEmpty(abcClass)) { - derivation = baseClass; + return baseClass; } else { - derivation = $"{baseClass}, {abcClass}"; + return $"{baseClass}, {abcClass}"; } - writer.WriteLine($"class {codeElement.Name}({derivation}):"); - writer.IncreaseIndent(); + } + + private void WriteInnerClassImportsAndDescriptions(ClassDeclaration codeElement, LanguageWriter writer, CodeNamespace parentNamespace) + { if (codeElement.Parent is CodeClass parent) { if (parent.Parent is CodeClass) // write imports for inner classes From 76a491c0419d8aa61c9a0dc9f1a7dccf223aa413 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Sat, 9 Nov 2024 13:18:52 +0300 Subject: [PATCH 07/11] add blocking issue --- it/config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/it/config.json b/it/config.json index a7006eeded..0f0115e8a3 100644 --- a/it/config.json +++ b/it/config.json @@ -242,6 +242,10 @@ { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/2484" + }, + { + "Language": "python", + "Rationale": "https://github.com/microsoft/kiota/issues/5744" } ] }, From 47353d129ba964870c383fd3cd43008e1d63f795 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Sat, 9 Nov 2024 13:32:32 +0300 Subject: [PATCH 08/11] update changelog entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86859b2723..668ff82e3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.20.0] - 2024-11-07 + ### Added ### Changed - +-Fixed Python error when a class inherits from a base class and inmplents an interface. +[5637](https://github.com/microsoft/kiota/issues/5637) - Fixed python generation client serailization failure str being quoted as "str" - Fixed Issue with primitive values being stringified in python python. [#5417](https://github.com/microsoft/kiota/issues/5417) - Fixed an issue where multipart request content would be ignored if other unstructured content was present in the description. [#5638](https://github.com/microsoft/kiota/issues/5638) From fd50d238bfeaf27870d349e6bc258218f3fc3a62 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Mon, 11 Nov 2024 10:54:23 +0300 Subject: [PATCH 09/11] Apply suggestions from code review Co-authored-by: Vincent Biret --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 668ff82e3c..275823148e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed --Fixed Python error when a class inherits from a base class and inmplents an interface. +- Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637) - Fixed python generation client serailization failure str being quoted as "str" - Fixed Issue with primitive values being stringified in python python. [#5417](https://github.com/microsoft/kiota/issues/5417) From fba358c9f488d370b6abc8409904e99bff14935a Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Mon, 11 Nov 2024 10:55:04 +0300 Subject: [PATCH 10/11] Update CHANGELOG.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 275823148e..89d9a9dfea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed -- Fixed Python error when a class inherits from a base class and implements an interface. -[5637](https://github.com/microsoft/kiota/issues/5637) +- Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637) - Fixed python generation client serailization failure str being quoted as "str" - Fixed Issue with primitive values being stringified in python python. [#5417](https://github.com/microsoft/kiota/issues/5417) - Fixed an issue where multipart request content would be ignored if other unstructured content was present in the description. [#5638](https://github.com/microsoft/kiota/issues/5638) From eea21e898f5a7b9783b3870aef2e4882bc522f57 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Mon, 11 Nov 2024 10:57:09 +0300 Subject: [PATCH 11/11] move changelog entry to unreleased section. --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89d9a9dfea..ae196fe262 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,13 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -## [1.20.0] - 2024-11-07 +- Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637) +## [1.20.0] - 2024-11-07 ### Added ### Changed -- Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637) + - Fixed python generation client serailization failure str being quoted as "str" - Fixed Issue with primitive values being stringified in python python. [#5417](https://github.com/microsoft/kiota/issues/5417) - Fixed an issue where multipart request content would be ignored if other unstructured content was present in the description. [#5638](https://github.com/microsoft/kiota/issues/5638)