Skip to content

Commit

Permalink
Use python Enum
Browse files Browse the repository at this point in the history
- Minor adjustment so we use Python Enum class instead of CSharp system
  enum for stubs, it's better supported by mypy
  • Loading branch information
Martin-Molinero committed Sep 6, 2024
1 parent f8204a4 commit 48c62ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions QuantConnectStubsGenerator/Renderer/ClassRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -43,6 +44,14 @@ private void RenderClassHeader(Class cls)

if (inherited.Count > 0)
{
for (var i = 0; i < inherited.Count; i++)
{
if (inherited[i].Equals("System.Enum", StringComparison.InvariantCultureIgnoreCase))
{
// 'Enum' is a python base type which is handled better by mypy if we used 'System' it assumes the enum value and causes a warning/missmatch
inherited[i] = "Enum";
}
}
Write($"({string.Join(", ", inherited)})");
}

Expand Down
2 changes: 2 additions & 0 deletions QuantConnectStubsGenerator/Renderer/NamespaceRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public override void Render(Namespace ns)
{
// Fix for Jedi; Include import of typing instead of using typing.overload
WriteLine("from typing import overload");
// fix for python enums
WriteLine("from enum import Enum");

var usedTypes = ns
.GetParentClasses()
Expand Down

0 comments on commit 48c62ac

Please sign in to comment.