- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Python Enum values (used to show default values in function signatures) are rendered ugly. #9272
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
Probably the repr() representation of default arguments is used, and it should be; that is supposed to give a string that, when evaluated, yields the value. Unfortunately, the enum.Enum implementation in Python does not honor this convention; their repr() includes the Enum value and the "<>" brackets. In an ideal world we could ask the enum.Enum people to fix that behavior; but I am afraid that would break quite a lot of code in the wild. The best course of action may be to special-case Enum types in autodoc. |
Searched the Python bug-tracker. There is some active discussion going on there to see if/how they should change repr for Enum classes: |
A workaround for the issue is to provide a __repr__ emplementation with Enum types, which may be a good idea anyway until the Python folks sort this out:
|
+1 Reasonable. |
Close #9272: autodoc: Render enum values for the default argument value better
Python Enum values (used to show default values in function signatures) are rendered ugly.
To Reproduce
I made a minimal example to show the issue:
https://github.com/sidneycadot/sphinx_issue_ugly_enum
Expected behavior
I would hope the signature rendered as:
Unfortunately, it renders as:
Environment info
The text was updated successfully, but these errors were encountered: