From 7ab2f7e8b05ced260c16e84f3ac3010784ae59e7 Mon Sep 17 00:00:00 2001 From: Martin Molinero Date: Mon, 11 May 2026 10:30:45 -0300 Subject: [PATCH] Fix security overloads order --- QuantConnectStubsGenerator.Tests/RendererTests.cs | 6 ++++++ QuantConnectStubsGenerator/Model/PythonType.cs | 8 ++++---- QuantConnectStubsGenerator/Renderer/ClassRenderer.cs | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/QuantConnectStubsGenerator.Tests/RendererTests.cs b/QuantConnectStubsGenerator.Tests/RendererTests.cs index 1a3d63a..53f1b0e 100644 --- a/QuantConnectStubsGenerator.Tests/RendererTests.cs +++ b/QuantConnectStubsGenerator.Tests/RendererTests.cs @@ -550,6 +550,7 @@ public List> TestMethod3(T1 t1Param, List { + public void TestMethod3(int number, DateTime time) {} } }" } @@ -605,8 +606,13 @@ class TestClass(QuantConnect.Test.TestGenericClass[QuantConnect.Symbol, datetime def test_method_1(self, t_1_param: typing.Union[QuantConnect.Symbol, str, QuantConnect.Data.Market.BaseContract, QuantConnect.Securities.Security], t_2_param: datetime.datetime) -> QuantConnect.Symbol: ... + @overload def test_method_3(self, t_1_param: typing.Union[QuantConnect.Symbol, str, QuantConnect.Data.Market.BaseContract, QuantConnect.Securities.Security], t_2_param: typing.List[System.Collections.Generic.Dictionary[QuantConnect.Symbol, typing.List[datetime.datetime]]]) -> typing.List[System.Collections.Generic.Dictionary[QuantConnect.Symbol, datetime.datetime]]: ... + + @overload + def test_method_3(self,number:int,time:typing.Union[datetime.datetime,datetime.date]) -> None: + ... " }).SetName("GeneratesMethodsWithSymbolImplicitConversionForInheritedGenericClasses"), diff --git a/QuantConnectStubsGenerator/Model/PythonType.cs b/QuantConnectStubsGenerator/Model/PythonType.cs index 9608527..7b776b5 100644 --- a/QuantConnectStubsGenerator/Model/PythonType.cs +++ b/QuantConnectStubsGenerator/Model/PythonType.cs @@ -21,13 +21,13 @@ namespace QuantConnectStubsGenerator.Model { public class PythonType : IEquatable { + public static readonly PythonType Security = new("Security", "QuantConnect.Securities"); public static readonly PythonType SymbolType = new PythonType("Symbol", "QuantConnect"); public static readonly PythonType ImplicitConversionParameterSymbolType = - CreateUnion(SymbolType, new PythonType("str"), new PythonType("BaseContract", "QuantConnect.Data.Market"), - new PythonType("Security", "QuantConnect.Securities")); + CreateUnion(SymbolType, new PythonType("str"), new PythonType("BaseContract", "QuantConnect.Data.Market"), Security); - public static readonly PythonType Any = new PythonType("Any", "typing"); - public static readonly PythonType None = new PythonType("None"); + public static readonly PythonType Any = new("Any", "typing"); + public static readonly PythonType None = new("None"); public string Name { get; set; } public string Namespace { get; set; } diff --git a/QuantConnectStubsGenerator/Renderer/ClassRenderer.cs b/QuantConnectStubsGenerator/Renderer/ClassRenderer.cs index 5743af7..113703e 100644 --- a/QuantConnectStubsGenerator/Renderer/ClassRenderer.cs +++ b/QuantConnectStubsGenerator/Renderer/ClassRenderer.cs @@ -111,7 +111,10 @@ private void RenderMethods(Class cls) .OrderBy(m => m.Name) .ThenBy(m => m.DeprecationReason == null ? 0 : 1) // pyobjects are converted into typing.any, we want those at the top so they resolve first which is what actually happens - .ThenBy(m => m.Parameters.Any(x => x.Type.Name.Equals("Any")) ? 0 : 1); + .ThenBy(m => m.HasPyObjectParameter + // a security is actually an any so it will match much lighter, so we place security methods before + ? 0 : m.Parameters.Any(x => x.Type.Name.Equals(PythonType.Security.Name) || x.Type.TypeParameters.Any(y => y.Name.Equals(PythonType.Security.Name))) + ? 1 : 2); foreach (var method in orderedMethods) {