8000 1774-ClassWithoutnamespace · pythonnet/pythonnet@eb4ce37 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb4ce37

Browse files
committed
1774-ClassWithoutnamespace
- Changed the behavior so that a .NET is always created when the base type is also a .NET type.
1 parent bfcf1d1 commit eb4ce37

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/runtime/Types/MetaType.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,18 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args,
128128
if (null != dict)
129129
{
130130
using var clsDict = new PyDict(dict);
131-
if (clsDict.HasKey("__assembly__") || clsDict.HasKey("__namespace__"))
131+
132+
if (clsDict.HasKey("__assembly__") || clsDict.HasKey("__namespace__")
133+
|| (cb.type.Valid && cb.type.Value != null && cb.type.Value.GetConstructor(Array.Empty<Type>()) != null))
132134
{
135+
if (!clsDict.HasKey("__namespace__"))
136+
{
137+
clsDict["__namespace__"] =
138+
(clsDict["__module__"].ToString()).ToPython();
139+
}
133140
return TypeManager.CreateSubType(name, base_type, clsDict);
134141
}
142+
135143
}
136144

137145
// otherwise just create a basic type without reflecting back into the managed side.

tests/test_subclass.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ class TestX(System.Object):
267267
def test_virtual_generic_method():
268268
class OverloadingSubclass(GenericVirtualMethodTest):
269269
__namespace__ = "test_virtual_generic_method_cls"
270+
class OverloadingSubclass2(OverloadingSubclass):
271+
pass
270272
obj = OverloadingSubclass()
271273
assert obj.VirtMethod[int](5) == 5
272274

0 commit comments

Comments
 (0)
0