.NET enums should not be automatically converted to Python int and back
See original GitHub issueFrom https://github.com/pythonnet/pythonnet/pull/1179
In Python, it should be possible to refer to enum members: MyEnum.Member
, and to create arbitrary enum values from int
explicitly like this: MyEnum(42)
. But by default a number and a value of some enum should not be freely convertible to each other. E.g. this should fail:
void Method(MyEnum value) => ...;
Python:
Method(42); # <- this should be a TypeError
We can add a generic enum codec, that could be enabled on demand to restore old behavior.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Pythonnet: Why are .NET enums type casted to int?
NET enums should not be automatically converted to Python int and back. The only workaround would be to add a C# helper dll...
Read more >Enum HOWTO — Python 3.11.4 documentation
An Enum is a set of symbolic names bound to unique values. They are similar to global variables, but they offer a more...
Read more >Making Enums (as always, arguably) more Pythonic
Though it's less dangerous for enum with string values than with int values (IntEnum is a bad idea IMHO), I prefer having 2...
Read more >How to use Enums when using Entity Framework Core with ...
A value conversion, unsurprisingly, automatically converts a value stored in the database into something else that you can use in code. So, in ......
Read more >Convert int to enum in C#
Here you will learn how to convert Int to Enum in C#. ... You can explicitly type cast an int to a particular...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@TheCollegedude I’ve just submitted a new PR for
master
branch to disable default conversion.If you are planning to stay on 2.5, you can use
IPyObjectDecoder
. It is marked obsolete, as it might change in 3.0 (so far it has not).@lostmsu Thanks. But, I have a problem with using 3.0 preview. I’m using it on Anaconda env with Mono on Mac. Is there any way to install preview with
conda install -c conda-forge
command?