Skip to content

"Incorrect" behavior of inheriting from class which is inherited from .Net class #264

Open

Description

@den-run-ai

https://mail.python.org/pipermail/pythondotnet/2016-April/001755.html

Deriving from a python class in Python that itself is derived from a .NET class doesn't work.

reported by @hhspiny and confirmed by @tonyroberts

Activity

  1. filmor commented on Aug 8, 2021

    @filmor
    Member

    The actual message was:

    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.

    This bug is still present and should be fixable by adjusting attribute lookup. @lostmsu Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions