[Python.NET] "Incorrect" behavior of inheriting from class which is inherited from .Net class

Hansong Huang hhspiny at pine.cc
Thu Aug 25 11:44:13 EDT 2016


Hi Denis,


There is no licenses term.  I simply used github to save files to work on between home and work.  it is free to use by anyone.


Since the current pythonnet does not really allow derive from class derived from .NET class. I can't really do what I intended to do, and therefore, I have not spent time on it further. I don't know much about the internal of python to contribute to correct the problem.


The framework currently in github does work fine using ExpandoObject class directly. so it would be ok to be used for simpler program.


Regards,


Hansong

________________________________
From: Denis Akhiyarov <denis.akhiyarov at gmail.com>
Sent: Thursday, August 25, 2016 11:15:37 AM
To: A list for users and developers of Python for .NET
Cc: hhspiny at pine.cc
Subject: Re: [Python.NET] "Incorrect" behavior of inheriting from class which is inherited from .Net class

Hi Hansong,

I noticed that you (@hhspiny) released your WPF adventures with pythonnet on github, but without a license:

https://github.com/hhspiny/WPFPy

Can you please indicate the license?

Hi Tony,

Please let me know how this subclassing (.NET -> Python -> Python) would work?

Thanks,
Denis

On Mon, Apr 11, 2016 at 2:04 AM, Tony Roberts <tony at pyxll.com<mailto:tony at pyxll.com>> wrote:
Hi,

yes, deriving from a python class in Python that itself is derived from a .net class doesn't work. Apologies, if I'd known that was what you were doing I could have saved you some time by telling you that earlier.

AFAIK this hasn't been created as an issue in github, so please if you could do that that would be helpful. It's probably not that hard to make work, but it's not something I've got time to look at myself right now I'm afraid. If anyone else wants to have a go and needs pointing in the right direction let me know.

Tony
On Mon, Apr 11, 2016 at 3:41 AM Hansong Huang <hhspiny at live.com<mailto:hhspiny at live.com>> wrote:
Hello,

This is related to previous investigation of inheriting from .NET interface class to create WPF MVVM structure.  As now I believe it has nothing to do with interface class, but instead caused by inheriting from .Net class overall.

please see the following code

import clr, System
class baseNA(System.Random):
    __namespace__ = "BaseNA"
    def __init__(self):
        super(baseNA,self).__init__()
#    @clr.clrmethod(System.String,[])
    def ToString(self):
        return "string"

class baseNB(baseNA):
    __namespace__ = "BaseNB"
    def __init__(self):
        super(baseNB,self).__init__()
bna = baseNA()
print bna.ToString()
print bna._Random__ToString()
bnb = baseNB()
print bnb.ToString()
print bnb._baseNA__ToString()
print bnb._Random__ToString()


This produces the following output
string
BaseNA.baseNA
BaseNB.baseNB
BaseNB.baseNB
BaseNB.baseNB

as you see, while baseNA -- the first level inherited class works fine. ToString() overrides System.Random.ToString()

But baseNB inherited from baseNA did not inherit ToString() method from baseNA, but rather inherited from System.Random.

Not sure if it is a bug in python.net<http://python.net> or was intended.

regards,

Hansong




_________________________________________________
Python.NET mailing list - PythonDotNet at python.org<mailto:PythonDotNet at python.org>
https://mail.python.org/mailman/listinfo/pythondotnet

_________________________________________________
Python.NET mailing list - PythonDotNet at python.org<mailto:PythonDotNet at python.org>
https://mail.python.org/mailman/listinfo/pythondotnet

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20160825/ce3d09c2/attachment-0001.html>


More information about the PythonDotNet mailing list