Skip to content

Commit

Permalink
Merge branch 'main' into andrueastman/pythonFix
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Nov 11, 2024
2 parents 1225097 + 5922724 commit be8d518
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Fixed python generation in scenarios with opening/closing tags for code comments. [#5636](https://github.com/microsoft/kiota/issues/5636)
- 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

Expand Down
2 changes: 1 addition & 1 deletion it/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
},
{
"Language": "python",
"Rationale": "https://github.com/microsoft/kiota/issues/5637"
"Rationale": "https://github.com/microsoft/kiota/issues/5744"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion it/php/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"microsoft/kiota-authentication-phpleague": "*"
},
"require-dev": {
"phpstan/phpstan": "^1.2.0"
"phpstan/phpstan": "^1.2.0 || ^2.0.0"
},
"minimum-stability": "stable",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mypy==1.13.0

mypy-extensions==1.0.0 ; python_version >= '3.5'

packaging==24.1 ; python_version >= '3.7'
packaging==24.2 ; python_version >= '3.7'

platformdirs==4.3.6 ; python_version >= '3.7'

Expand Down Expand Up @@ -64,7 +64,7 @@ wrapt==1.15.0 ; python_version < '3.11'

yapf==0.40.2

zipp==3.20.2 ; python_version >= '3.7'
zipp==3.21.0 ; python_version >= '3.7'

aiohttp==3.10.10 ; python_version >= '3.6'

Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Kiota.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="YamlDotNet" Version="16.1.3" />
<PackageReference Include="YamlDotNet" Version="16.2.0" />
<ProjectReference Include="..\Kiota.Generated\KiotaGenerated.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
Expand Down
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

0 comments on commit be8d518

Please sign in to comment.