Skip to content

Show enum members in Annotated types like Literal does - #14654

Open
gyanu2507 wants to merge 5 commits into
sphinx-doc:masterfrom
gyanu2507:annotated-enum-display
Open

gyanu2507 wants to merge 5 commits into
sphinx-doc:masterfrom
gyanu2507:annotated-enum-display

Conversation

@gyanu2507

Copy link
Copy Markdown

Annotated[int, Color.red] was going through repr(), so autodoc printed <Color.red: 'red'>. Literal already formats enum members as :py:attr: links — reused that for Annotated metadata.

Fixes #14653

repr() was dumping things like <Color.red: 'red'> into the docs.
@gyanu2507

Copy link
Copy Markdown
Author

The red CI here isn't from this change — it's Pygments 2.21.0, which stopped escaping " as &quot; in its HTML output.

Six tests fail, all of them string-comparing highlighted HTML:

  • test_highlighting.py::test_default_highlight
  • test_builders/test_build_html_code.py::test_html_code_role
  • test_extensions/test_ext_viewcode.py::test_viewcode
  • test_extensions/test_ext_viewcode.py::test_viewcode_linenos
  • test_intl/test_intl.py::test_additional_targets_should_be_translated
  • test_intl/test_intl.py::test_additional_targets_should_not_be_translated

None of them touch sphinx/util/typing.py. To confirm, I checked out this PR's branch point (e44a40e, unmodified master) with Pygments 2.21.0 pinned and got the identical six failures; pinning back to 2.19.2 makes both the branch point and this branch fully green. e44a40e's own CI run was green because it predates the 2.21.0 release on 2026-08-17.

Happy to send the escaping updates as a separate PR if that's useful, or rebase this one once that's sorted — just say which you'd prefer.

No code change. The previous CI run predates recent master activity;
re-trigger to see whether the Pygments HTML escaping failures are still
present on tip.
@gyanu2507

Copy link
Copy Markdown
Author

Pushed an empty commit to re-run CI on current master.

The earlier red jobs were highlighting tests that assert HTML containing &quot; (e.g. test_html_code_role, test_viewcode, test_default_highlight). That tracks Pygments output escaping, not the Annotated-enum formatting change in this PR. If tip is still red the same way, it is a base-branch / dependency issue rather than this diff.

@azmeuk azmeuk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This fixes the issue I reported. 👌

@azmeuk

azmeuk commented Nov 20, 2026

Copy link
Copy Markdown

@gyanu2507 are the CI failures due to your code? I guess this PR won't be merged until they are fixed. Would you have some time to spend on it so it gives this PR a chance?

@gyanu2507

Copy link
Copy Markdown
Author

No, the failures weren't from this change. The last CI run (https://github.com/sphinx-doc/sphinx/actions/runs/33652199657, Sept 2) ran against a master that was 48 commits behind, and two things on master were broken at that point:

  • Every Python job, Windows and macOS failed the same 6 tests (test_default_highlight, test_html_code_role, test_viewcode, test_viewcode_linenos and the two test_additional_targets_* tests in test_intl). Those compare highlighted HTML containing &quot;, which Pygments 2.21.0 stopped emitting. Master fixed it in b04a210 (Tests: adapt HTML escaping to pygments v2.21.0 change-in-behaviour #14611).
  • LaTeX and Docutils HEAD failed 44 tests with TypeError: unsupported operand type(s) for +: 'int' and 'str' in sphinx/writers/latex.py and sphinx/writers/text.py, from Docutils pre-release changes. Master fixed that in d19cbb5 ("Fix tests for Docutils 1.0 pre-releases").

None of the failing tests touch sphinx/util/typing.py. Master CI has been green since Oct 23 apart from one linkcheck timeout on 3.15t (run 40967878253).

I merged current master into the branch (93a44a8) and moved the changelog entry, which the merge had left under 9.1.1, into the 9.3.0 "Bugs fixed" section (fa4e7ec). Locally with Pygments 2.21.0 and Docutils 0.23 on Python 3.13, test_util_typing, test_util_inspect, tests/test_ext_autodoc and the previously failing highlighting, viewcode, text-builder and intl tests all pass (433 passed). CI should go green once it runs on the new head.

Thanks for checking the fix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad display of annotated enum members

2 participants