8000 Object identity, Interfaces and Attributes by rmadsen-ks · Pull Request #2019 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Object identity, Interfaces and Attributes #2019

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 1 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
Prev Previous commit
Next Next commit
1774-ClassWithoutnamespace
- Changed the behavior so that a .NET is always created when the base type is also a .NET type.
  • Loading branch information
rmadsen-ks committed Oct 31, 2022
commit eb4ce37eb5d666a48c7119420ef0e5e272c51d02
10 changes: 9 additions & 1 deletion src/runtime/Types/MetaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,18 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args,
if (null != dict)
{
using var clsDict = new PyDict(dict);
if (clsDict.HasKey("__assembly__") || clsDict.HasKey("__namespace__"))

if (clsDict.HasKey("__assembly__") || clsDict.HasKey("__namespace__")
|| (cb.type.Valid && cb.type.Value != null && cb.type.Value.GetConstructor(Array.Empty<Type>()) != null))
{
if (!clsDict.HasKey("__namespace__"))
{
clsDict["__namespace__"] =
(clsDict["__module__"].ToString()).ToPython();
}
Comment on lines +152 to +156
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't introduce breaking changes

return TypeManager.CreateSubType(name, base_type, clsDict);
}

}

// otherwise just create a basic type without reflecting back into the managed side.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ class TestX(System.Object):
def test_virtual_generic_method():
class OverloadingSubclass(GenericVirtualMethodTest):
__namespace__ = "test_virtual_generic_method_cls"
class OverloadingSubclass2(OverloadingSubclass):
pass
obj = OverloadingSubclass()
assert obj.VirtMethod[int](5) == 5

Expand Down
0