Allow conversion of number to enum type when underlying type is assignable#1179
Allow conversion of number to enum type when underlying type is assignable#1179slide wants to merge 2 commits intopythonnet:masterfrom slide:enum_conversion
Conversation
In .NET you can do the following:
```
enum FooEnum {
One = 1,
Three = 3,
Four = 4,
}
FooEnum x = (FooEnum)2;
```
This patch allows this from Python code as well.
|
@slide in .NET you can't just assign a numeric value to an enum. You have to make an explicit cast for a good reason. The most pythonic way I see this could work is |
|
That's true, it does require the typecast. This only allows assignment/coercion when the underlying type is assignable, is that still too lenient? |
|
@slide oh, I checked the code of I actually think Python.NET should have required an explicit cast from the beginning, and should not have converted enum values to Python Summoning @filmor into conversation. |
|
Ok, thanks, I'll see if I can work on something like that. |
What does this implement/fix? Explain your changes.
In .NET you can do the following:
This patch allows this from Python code as well.
Does this close any currently open issues?
Possibly #935
Any other comments?
I would definitely like eyes on this, I am possibly missing something :-)
Checklist
Check all those that are applicable and complete.
AUTHORSCHANGELOG