Skip to content

python 支持使用 [] 传入泛型来构建类,添加puerts.generic_method方法,目前只支持静态方法,完善puerts.gen_iterator#2293

Merged
chexiongsheng merged 8 commits intoTencent:masterfrom
realybin:feat/backend
Mar 5, 2026

Conversation

@realybin
Copy link
Copy Markdown
Contributor

@realybin realybin commented Mar 5, 2026

from System import Console, Int32, String
from System.Collections.Generic import List__T1

List_T1_Int = List__T1[Int32]
myList = List_T1_Int()

myList.Add(42)
myList.Add(100)
iter = puerts.gen_iterator(myList)

for i in iter:
    Console.WriteLine("Item in myList: " + str(i))

import GenericTest__T1
GenericTest_T1_Int = GenericTest__T1[Int32]

StaticTestMethod_Int32 = puerts.generic_method(GenericTest_T1_Int, 'StaticTestMethod', Int32)
StaticTestMethod_Int32(456)
StaticTestMethod_Int32_Int32 = puerts.generic_method(GenericTest_T1_Int, 'StaticTestMethod', Int32, Int32)
StaticTestMethod_Int32_Int32(789)

import GenericTest2__T2
GenericTest2_Int_String = GenericTest2__T2[Int32, String]
t2 = GenericTest2_Int_String()
public class GenericTest2<T1, T2>
{
    public GenericTest2()
    {
        Console.WriteLine("GenericTest2 constructor called with types: " + typeof(T1).Name + ", " + typeof(T2).Name);
    }
}

public class GenericTest<T1>
{
    public T? TestMethod<T>(int param)
    {
        Console.WriteLine("GenericTest.TestMethod called with type: " + typeof(T).Name + " and value: " + param);
        return default(T);
    }
    
    public static T StaticTestMethod<T>(int param)
    {
        Console.WriteLine("GenericTest.StaticTestMethod called with type: " + typeof(T).Name + " and value: " + param);
        return default(T);
    }
    public static T1 StaticTestMethod<T1, T2>(int param)
    {
        Console.WriteLine("GenericTest.StaticTestMethod called with type: " + typeof(T1).Name + ", " + typeof(T2).Name + " and value: " + param);
        return default(T1);
    }
}

@realybin realybin changed the title python 支持使用 [] 传入泛型来构建类,添加puerts.generic_method方法,目前只支持静态方法 python 支持使用 [] 传入泛型来构建类,添加puerts.generic_method方法,目前只支持静态方法,完善puerts.gen_iterator Mar 5, 2026
@chexiongsheng chexiongsheng merged commit ebf1235 into Tencent:master Mar 5, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants