- Notifications
You must be signed in to change notification settings - Fork749
Open
Description
Environment
- Pythonnet version: 3.0.5
- Python version: 3.11
- Operating System: Windows 11
- .NET Runtime: 9.0
Details
When instantiating a C# class in a Python module, two C# objects are created:
C# class:
classSomeClass{publicSomeClass(){}publicSomeClass(intarg1,stringarg2){}}
Python module
obj=SomeClass()
The default constructorSomeClass()
is called twice inMetaType.tp_call
, first byusing NewReference obj = NativeCall.Call_3(tp_new, tp, args, kw);
and then bytype.Init(obj.Borrow(), args, kw)
.
If Python does this:
obj=SomeClass(1,"str")
Thenusing NewReference obj = NativeCall.Call_3(tp_new, tp, args, kw);
calls the default constructor and thentype.Init(obj.Borrow(), args, kw)
calls the one with arguments.
Is this an expected behaviour? Is there a workaround or fix for this? I am working with a case where I really don't whant the constructor to be called twice.
Is this related to#495?
Thank you in advance.
Metadata
Metadata
Assignees
Labels
No labels