Skip to content

F# records are not accesssible if generic and inside a module #574

Open

Description

@stevehv

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.5.3
  • Operating System: Windows 10
  • F# 4.4.1.0, .NET Framework 4.7

Details

F# records are not accessible in pythonnet if generic AND inside a module.
Sample F# code, all types but MyRecordD are accessible from Pythonnet:

namespace MyNamespace

type MyRecordA = { a: int; b: int }
type MyRecordB<'t> = { a: 't; b: 't }

module MyModule = 
    type MyRecordC = { a: int; b: int }
    type MyRecordD<'t> = { a: 't; b: 't }

Python code, ony the last line causes an error:

from clr import MyNamespace
MyNamespace.MyRecordA                             # Ok
MyNamespace.MyRecordB[System.String]          # Ok
MyNamespace.MyModule.MyRecordC                    # Ok
MyNamespace.MyModule.MyRecordD[System.String] # AttributeError: type object 'MyModule' has no attribute 'MyRecordD'

I noticed that dir(MyNamespace) contains 'MyRecordA', 'MyRecordB', 'MyRecordB`1' while dir(MyNamespace.MyModule) only contains 'MyRecordC', 'MyRecordD`1' but no 'MyRecordD'.

Activity

  1. den-run-ai commented on Nov 18, 2017

    @den-run-ai
    Contributor

    Can you show your F# version and the code for MyRecord?
    Did you try accessing this F# type via System.Reflection in Python?

  2. den-run-ai commented on Nov 18, 2017

    @den-run-ai
    Contributor

    Or using getattr

  3. dmitriyse commented on Nov 18, 2017

    @dmitriyse
    Contributor

    Your clr.MyNamespace.MyRecord is generic with one argument, that's why CLR shows `1

  4. den-run-ai commented on Nov 18, 2017

    @den-run-ai
    Contributor

    @stevehv also what happens when you try accessing your F# record without clr.? That should not be required for .NET namespaces imported properly through pythonnet - they should act like normal Python namespaces.

  5. stevehv commented on Nov 19, 2017

    @stevehv
    Author

    Owing to some sleep deprivation the problematic F# code was not what I originally thought it was.
    I have updated the original issue so that it is now reproducible, apologies for any confusion.

    Accessing without clr. did not make a difference.
    getattr did not work either:

    getattr(MyNamespace.MyModule, 'MyRecordD`1')[System.String] # TypeError: no type matches params
  6. den-run-ai commented on Nov 19, 2017

    @den-run-ai
    Contributor

    Can you show output of MyNamespace.MyModule.MyRecordD.Overloads?

  7. stevehv commented on Nov 19, 2017

    @stevehv
    Author
    MyNamespace.MyModule.MyRecordD.Overloads
    AttributeError: type object 'MyModule' has no attribute 'MyRecordD'
    

    System.Reflection dll.GetType("MyNamespace.MyModule+MyRecordD`1")) seems to work ok, but doing every function call using reflection makes code unreadable.

  8. changed the title [-]F# record MyRecord becomes MyRecord`1 in pythonnet[/-] [+]F# record not accesssible if generic and inside a module[/+] on Nov 20, 2017
  9. changed the title [-]F# record not accesssible if generic and inside a module[/-] [+]F# records are not accesssible if generic and inside a module[/+] on Nov 20, 2017
  10. den-run-ai commented on Nov 27, 2017

    @den-run-ai
    Contributor

    @stevehv any idea how this F# code looks like in C#? i'm not sure if this is only IL feature or available in C# too?

  11. lostmsu commented on Sep 17, 2022

    @lostmsu
    Member

    This should be added to #1374

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