- Notifications
You must be signed in to change notification settings - Fork748
use enum name in repr#2239
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
lostmsu commentedSep 18, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Can you please make the format similar to Python's >>>fromenumimportEnum>>>classColor(Enum):...RED=1...GREEN=2...>>>repr(Color.GREEN)'<Color.GREEN: 2>' I suggest to use decimal values when enum is a regular enum, and either binary or hexadecimal when it has P.S. Disregard the Mac and ARM failures, they are caused by our test infra. |
@lostmsu Done - but I'm not really that happy with the Flags case. |
@koubaa both of course. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
@lostmsu done. The switch case isn't so pretty, but I couldn't think of a way to improve it. here's a minimal compiler explorer link with that logic if anyone wants to try and see if they can improve it:https://godbolt.org/z/dYG6sdnKo |
lostmsu commentedSep 21, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@koubaa tryusing Convert.ChangeType stringConvertFlags(Enumvalue){TypeprimitiveType=value.GetType().GetEnumUnderlyingType();stringformat="X"+(Marshal.SizeOf(primitiveType)*2).ToString(CultureInfo.InvariantCulture);varprimitive=(IFormattable)Convert.ChangeType(value,primitiveType);returnprimitive.ToString(format,null);}stringConvertValue(Enumvalue){TypeprimitiveType=value.GetType().GetEnumUnderlyingType();returnConvert.ChangeType(value,primitiveType).ToString()!;} |
Uh oh!
There was an error while loading.Please reload this page.
mirror of upstream PR:pythonnet/pythonnet#2239
Uh oh!
There was an error while loading.Please reload this page.
What does this implement/fix? Explain your changes.
Proposal tofix#2238
Before the changes:
IronPython (as a reference):
With these changes:
Checklist
AUTHORS
CHANGELOG