You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to have the ability to extract the value of a .Net Enum via python. One can do that using MyEnum.value__, however it seems logical that you should do it using int(MyEnum).
If I remember correctly, we removed the code, that converted any enum value to an integer implicitly when passed to Python. You could never previously get raw enum value in Python, it always just saw integers. So the corresponding type never had __int__ implementation.
Activity
filmor commentedon Nov 23, 2021
This is possible using codecs, though they are /really/ unergonomic so far when using them from Python:
The decoder is buggy right now (fix in #1621).
@lostmsu Do you have a proposal for a nice ergonomic Python API for this? Should we enable some encoders/decoders by default unless told otherwise?
lostmsu commentedon Nov 23, 2021
I don't think enabling codecs by default is a good idea, unless they are 1:1 exact rountrippable mappings.
As for the more ergonomic Python APIs, somebody more proficient with Python should propose those.
lostmsu commentedon Nov 23, 2021
As for the issue at hand, .NET enums should implement
__int__or its C API alternative,nb_intforint(Keys.Control)to work, not a codec.filmor commentedon Nov 23, 2021
Isn't that something that we explicitly removed?
lostmsu commentedon Nov 23, 2021
If I remember correctly, we removed the code, that converted any enum value to an integer implicitly when passed to Python. You could never previously get raw enum value in Python, it always just saw integers. So the corresponding type never had
__int__implementation.saroad2 commentedon Nov 29, 2021
So if I understand you correctly, we all agree that adding a default
__int__method for all C# enums is a wise idea?I would have implemented this ability myself, but I have zero knowledge in C#. Let me know if I can help you somehow make this ability happen.
provide `__int__` instance method on .NET enum types to support int(E…
provide `__int__` instance method on .NET enum types to support int(E…
provide `__int__` instance method on .NET enum types to support int(E…
provide `__int__` instance method on .NET enum types to support int(E…
provide `__int__` instance method on .NET enum types to support int(E…
provide `__int__` instance method on .NET enum types to support int(E…