8000 F# records are not accesssible if generic and inside a module · Issue #574 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content
< 8000 /div>

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stevehv opened this issue Nov 18, 2017 · 9 comments
Open

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

stevehv opened this issue Nov 18, 2017 · 9 comments

Comments

@stevehv
Copy link
stevehv commented Nov 18, 2017

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'.

@den-run-ai
Copy link
Contributor

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

@den-run-ai
Copy link
Contributor

Or using getattr

@dmitriyse
Copy link
Contributor

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

@den-run-ai
Copy link
Contributor
den-run-ai commented Nov 18, 2017

@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.

@stevehv
Copy link
Author
stevehv commented Nov 19, 2017

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

@den-run-ai
Copy link
Contributor

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

@stevehv
Copy link
Author
stevehv commented Nov 19, 2017
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.

@stevehv stevehv changed the title F# record MyRecord becomes MyRecord`1 in pythonnet F# record not accesssible if generic and inside a module Nov 20, 2017
@stevehv stevehv changed the title F# record not accesssible if generic and inside a module F# records are not accesssible if generic and inside a module Nov 20, 2017
@den-run-ai
Copy link
Contributor
8BBB

@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?

@lostmsu
Copy link
Member
lostmsu commented Sep 17, 2022

This should be added to #1374

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0