Title: Must explicitly convert IntEnum to int to use equality comparison · Issue #1848 · pythonnet/pythonnet · GitHub
Open Graph Title: Must explicitly convert IntEnum to int to use equality comparison · Issue #1848 · pythonnet/pythonnet
X Title: Must explicitly convert IntEnum to int to use equality comparison · Issue #1848 · pythonnet/pythonnet
Description: Environment Pythonnet version: 3.0.0-a2 Python version: 3.9.10 Operating System: Windows 10 Pro - 21H2 - 19044.1766 .NET Runtime: Unity/Mono Details When trying to compare the equality of Python IntEnum instances from C#, they must be ex...
Open Graph Description: Environment Pythonnet version: 3.0.0-a2 Python version: 3.9.10 Operating System: Windows 10 Pro - 21H2 - 19044.1766 .NET Runtime: Unity/Mono Details When trying to compare the equality of Python In...
X Description: Environment Pythonnet version: 3.0.0-a2 Python version: 3.9.10 Operating System: Windows 10 Pro - 21H2 - 19044.1766 .NET Runtime: Unity/Mono Details When trying to compare the equality of Python In...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/1848
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Must explicitly convert IntEnum to int to use equality comparison","articleBody":"### Environment\r\n\r\n- Pythonnet version: 3.0.0-a2\r\n- Python version: 3.9.10\r\n- Operating System: Windows 10 Pro - 21H2 - 19044.1766\r\n- .NET Runtime: Unity/Mono\r\n\r\n### Details\r\n\r\n- When trying to compare the equality of Python IntEnum instances from C#, they must be explicitly converted to an int.\r\n\r\n\r\n```python\r\n# in my_module.py file\r\nclass MyEnum(enum.IntEnum):\r\n OK = 1\r\n ERROR = 2\r\n\r\ndef get_status():\r\n return MyEnum.OK \r\n```\r\n\r\nNo crash.\r\n\r\n```csharp\r\nPythonRunner.EnsureInitialized();\r\nusing (Py.GIL())\r\n{ \r\n // Import our module\r\n dynamic my_module = Py.Import(\"my_module\");\r\n dynamic MyEnum= my_module .MyEnum; \r\n // Call the Python func on C# side\r\n dynamic status = my_module.get_status();\r\n if ((int)status == (int)MyEnum.OK) // \u003c-- have to convert to int\r\n if (status == MyEnum.OK) // when not converting to int, they are not evaluated as equal (no crash)\r\n}\r\n```\r\n","author":{"url":"https://github.com/baptisteguidoux","@type":"Person","name":"baptisteguidoux"},"datePublished":"2022-06-30T18:55:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1848/pythonnet/issues/1848"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:68f163a5-8301-c96a-b834-77810fa3af8a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A760:2AE294:1FA380D:2AA047D:69702DAD |
| html-safe-nonce | 656c9cd526421940ff00e54b5cd1af25e5a97dd78f9972e72d8651fe224bce36 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzYwOjJBRTI5NDoxRkEzODBEOjJBQTA0N0Q6Njk3MDJEQUQiLCJ2aXNpdG9yX2lkIjoiNTA3ODg1NzI0OTQzNDExOTU5NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0e6abb8008557cb63908cbcb01dcb2ddf3c5aa7479ee250683233333df28b6b8 |
| hovercard-subject-tag | issue:1290520698 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonnet/pythonnet/1848/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6d5702f1db7a4f3e71c1ac6ff0e834cf8d74bdc3ba45ceac8eae08c721277a9a/pythonnet/pythonnet/issues/1848 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6d5702f1db7a4f3e71c1ac6ff0e834cf8d74bdc3ba45ceac8eae08c721277a9a/pythonnet/pythonnet/issues/1848 |
| og:image:alt | Environment Pythonnet version: 3.0.0-a2 Python version: 3.9.10 Operating System: Windows 10 Pro - 21H2 - 19044.1766 .NET Runtime: Unity/Mono Details When trying to compare the equality of Python In... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | baptisteguidoux |
| hostname | github.com |
| expected-hostname | github.com |
| None | 01fa379f5de85ef8e791d09724e69709ce9eb9595278316e0a921312dc88e0bc |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | dda91974c069382b0dfa47b2da7e28bd061c8331 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width