Skip to content
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

TypeError when calling a method with an enum argument #935

Closed
vladt3 opened this issue Aug 6, 2019 · 3 comments
Closed

TypeError when calling a method with an enum argument #935

vladt3 opened this issue Aug 6, 2019 · 3 comments

Comments

@vladt3
Copy link

vladt3 commented Aug 6, 2019

Environment

  • Pythonnet version: 2.4.0
  • Python version: 3.6
  • Operating System: Windows10

Details

  • calling a method that uses C# enum as an argument with the enum fails with TypeError: No method matches given arguments for XXX

The enum comes in Python as an int, and since the method signature is not int, it fails.

I cannot see how to force the typecast, or whether I could somehow force the method call directly (overloads lists the method, but I can't figure out whether I can call directly).

Searching google did not return anything recent, although some older comments (2017/18 IIRC) indicated there was a fix for this?

@Cronan
Copy link
Contributor

Cronan commented Aug 12, 2019

This kind of thing should work, I believe ...

from Tests import TestClass, TestEnum
a = TestClass()
a.EnumMethod[TestEnum](TestEnum.FirstValue)

@vladt3
Copy link
Author

vladt3 commented Aug 12, 2019

Thanks, it does indeed. Maybe there should be some FAQ that would cover things like these?

@vladt3 vladt3 closed this as completed Aug 12, 2019
@Cronan
Copy link
Contributor

Cronan commented Aug 12, 2019

Thanks, it does indeed. Maybe there should be some FAQ that would cover things like these?

Thanks, that's a good idea

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

2 participants