Skip to content

Classes without __namespace__ cannot be used for reflection #1774

Description

@rmadsen-ks

Environment

  • Pythonnet version: 3.0.0-preview2022-04-11
  • Python version: 3.10
  • Operating System: MacOS
  • .NET Runtime: .net 6

Details

My software does lots of reflection on "plugin" types. Simply inheriting from a specific type is enough in C#, but when I use python.net I also have to define __namespace__. Since my users generally have the namespace being ., there is no logic reason for them to have to do this.

I can see which part of the code causes this:

    // from MetaType.cs:133 (git: 7247da55c174be1b733e5f9fc4e1c356f6c42dc4)
    if (clsDict.HasKey("__assembly__") || clsDict.HasKey("__namespace__"))
    {
            return TypeManager.CreateSubType(name, base_type, clsDict);
    }

I am wonder if we could broaden the cases where TypeManager.CreateSubType is used. For example in cases where the super class is a type created with CreateSubType, or just any .NET class in general. Maybe it could also be if the super class implements a specific interface.

_TODO_

Add a way to not have to specify namespace in the class in order for reflection to work.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions