Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python failing integration tests #5724

Merged
merged 13 commits into from
Nov 11, 2024
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 implements an interface.
baywet marked this conversation as resolved.
Show resolved Hide resolved
[5637](https://github.com/microsoft/kiota/issues/5637)
andrueastman marked this conversation as resolved.
Show resolved Hide resolved
- 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)
Expand Down
4 changes: 2 additions & 2 deletions it/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
},
{
"Language": "python",
"Rationale": "https://github.com/microsoft/kiota/issues/5637"
"Rationale": "https://github.com/microsoft/kiota/issues/5744"
andrueastman marked this conversation as resolved.
Show resolved Hide resolved
}
]
},
Expand All @@ -262,4 +262,4 @@
"Suppressions": [],
"IdempotencySuppressions": []
}
}
}
34 changes: 30 additions & 4 deletions src/Kiota.Builder/Writers/Python/CodeClassDeclarationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -34,15 +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 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;
writer.WriteLine($"class {codeElement.Name}({derivation}):");
writer.IncreaseIndent();
string.Empty;
if (string.IsNullOrEmpty(baseClass))
{
return abcClass;
}
else if (string.IsNullOrEmpty(abcClass))
{
return baseClass;
}
else
{
return $"{baseClass}, {abcClass}";
}
}

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
Expand Down
Loading