-
Notifications
You must be signed in to change notification settings - Fork 751
.NET enums should not be automatically converted to Python int and back #1220
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
Comments
This is related to #1099 |
I support that. This would solve a lot of problems, e.g.: https://stackoverflow.com/q/65805093/7556646. |
Is there a workaround? I tried using IPyObjectDecoder but it is marked as "obsolete". The wiki, where I found it, seems to be |
- enums are no longer converted to and from PyLong automatically pythonnet#1220 - one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10) - in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion - legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs
- enums are no longer converted to and from PyLong automatically pythonnet#1220 - one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10) - in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion - legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs
- enums are no longer converted to and from PyLong automatically pythonnet#1220 - one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10) - in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion - legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs
@TheCollegedude I've just submitted a new PR for If you are planning to stay on 2.5, you can use |
- enums are no longer converted to and from PyLong automatically pythonnet#1220 - one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10) - in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion - legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs
- enums are no longer converted to and from PyLong automatically pythonnet#1220 - one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10) - in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion - legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs - flags enums support bitwise ops via EnumOps class
- enums are no longer converted to and from PyLong automatically pythonnet#1220 - one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10) - in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion - legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs - flags enums support bitwise ops via EnumOps class
- enums are no longer converted to and from PyLong automatically pythonnet#1220 - one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10) - in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion - legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs - flags enums support bitwise ops via EnumOps class
- enums are no longer converted to and from PyLong automatically #1220 - one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10) - in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion - legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs - flags enums support bitwise ops via EnumOps class
I think this should be a hot fix. If there is C# codes like the below: namespace myname.mynamespace
{
public static partial class MyClass
{
public static IEnumerable<MyResult> MyFunc<TSometing>(
this IEnumerable<TSomething> something,
int num)
where TSomething : ISomething
{
// do something.
}
public static IEnumerable<MyResult> MyFunc<TSometing>(
this IEnumerable<TSomething> something,
int num,
MyEnum myenum = MyEnum.Elem)
where TSomething : ISomething
{
// do something.
}
}
} The second overloaded method can never be called: from myname.mynamespace import MyClass
from myname.mynamespace import MyEnum
#Something is sub-class of ISomething .
MyClass.MyFunc[Something](something_list, 10, MyEnum.Elem2)
>>>
TypeError: No method matches given arguments for MyFunc: (<class 'System.Collections.Generic.0, Culture=neutral, PublicKeyToken=null]]'>, <class 'int'>, <class 'int'>) I also tried to call the second one manually by using |
@LeeDongGeon1996 this has already been fixed in pythonnet 3.0 previews. We do not plan to backport it. |
@lostmsu Thanks. But, I have a problem with using 3.0 preview. |
…ress the integer values per Pythonnet v3.0 changes pythonnet/pythonnet#1220
From #1179
In Python, it should be possible to refer to enum members:
MyEnum.Member
, and to create arbitrary enum values fromint
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:Python:
We can add a generic enum codec, that could be enabled on demand to restore old behavior.
The text was updated successfully, but these errors were encountered: