Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix implementing a generic interface with a Python class#1998

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Add tests for deriving a Python subclass from a generic interface
  • Loading branch information
@filmor
filmor committedNov 2, 2022
commit461c9c708ce36a054c363700f232a1b5df09ed2e
23 changes: 22 additions & 1 deletionsrc/testing/interfacetest.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,7 +79,7 @@ private interface IPrivate
{
}
}

public interface IOutArg
{
string MyMethod_Out(string name, out int index);
Expand All@@ -93,4 +93,25 @@ public static int CallMyMethod_Out(IOutArg myInterface)
return index;
}
}

public interface IGenericInterface<T>
{
public T Get(T x);
}

public class SpecificInterfaceUser
{
public SpecificInterfaceUser(IGenericInterface<int> some, int x)
{
some.Get(x);
}
}

public class GenericInterfaceUser<T>
{
public GenericInterfaceUser(IGenericInterface<T> some, T x)
{
some.Get(x);
}
}
}
23 changes: 22 additions & 1 deletiontests/test_subclass.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
import System
import pytest
from Python.Test import (IInterfaceTest, SubClassTest, EventArgsTest,
FunctionsTest)
FunctionsTest, IGenericInterface)
from System.Collections.Generic import List


Expand All@@ -29,6 +29,17 @@ def bar(self, x, i):
return InterfaceTestClass


def interface_generic_class_fixture(subnamespace):

class GenericInterfaceImpl(IGenericInterface[int]):
__namespace__ = "Python.Test." + subnamespace

def Get(self, x):
return x

return GenericInterfaceImpl


def derived_class_fixture(subnamespace):
"""Delay creation of class until test starts."""

Expand DownExpand Up@@ -306,3 +317,13 @@ class Derived(BaseClass):

import gc
gc.collect()

def test_generic_interface():
from System import Int32
from Python.Test import GenericInterfaceUser, SpecificInterfaceUser

GenericInterfaceImpl = interface_generic_class_fixture(test_generic_interface.__name__)

obj = GenericInterfaceImpl()
SpecificInterfaceUser(obj, Int32(0))
GenericInterfaceUser[Int32](obj, Int32(0))

[8]ページ先頭

©2009-2025 Movatter.jp