Skip to content

Render only class docstrings; test constructors have none - #2221

Open
bernardhaddad wants to merge 1 commit into
PyCalendar:mainfrom
bernardhaddad:docs-autoclass-content-1620
Open

bernardhaddad wants to merge 1 commit into
PyCalendar:mainfrom
bernardhaddad:docs-autoclass-content-1620

Conversation

@bernardhaddad

Copy link
Copy Markdown

Linked issue

Description

The API reference showed "Create new instance of ..." text that Python generates for NamedTuple constructors. Sphinx now renders only the class docstring, a new test fails if any __init__ or __new__ gets its own docstring, and the style guide says so.

The vague binary.py docstring item from the issue is not part of this PR.

Checklist

  • I added a change log entry, following the instructions in all subsections under Change log requirements.
  • I followed icalendar's Artificial intelligence policy and disclosed my Responsible AI use in my commit messages, if applicable.
  • I added or updated tests, if applicable.
  • I ran and ensured all tests pass locally by following Run tests.
  • I added or edited documentation as necessary, both as docstrings to be rendered in the API documentation and narrative documentation, following the Style guide.

Additional information

This description was drafted with Claude Code, like the change itself (disclosed in the commit message and change log entry). I reviewed it and I'm happy to make any changes you ask for.

Contributes to PyCalendar#1620.

Set autoclass_content to "class", so the API reference shows the class
docstring only. The pages for AdrFields, NFields and Alarm.Triggers lose
the "Create new instance of ..." text that Python generates for a
NamedTuple's __new__.

Add test_no_init_docstrings.py: it walks every icalendar module and fails
if a class's own __init__ or __new__ has a docstring. Constructors that
Python generates (NamedTuple) are skipped, because their code is not in
the class's module. Update the style guide to describe the new setup.

AI use: Claude Opus 5.5 in Claude Code.
Prompt (summary): find an open beginner issue in icalendar and prepare a
pull request for it. Claude checked that no __init__ or __new__
docstrings remain in src/, wrote the test and checked that it fails when
a docstring is added to vText.__new__, changed the Sphinx setting,
updated the style guide, built the docs before and after the change to
compare warnings and rendered pages, and ran the test suite and ruff.
Output: this commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@stevepiercy stevepiercy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your contribution. Just a minor tweak to the docs, and I'll approve.

I didn't realize we had completed migration of all docstrings from all the class's __init__ and __new__ methods, which the tests confirm. Nice work!

Sphinx will automatically append the ``__init__`` or ``__new__`` docstrings to the class's docstring, which may render the documentation in a confusing manner to the reader.

If you find docstrings in a class's ``__init__`` or ``__new__`` methods, then please create a pull request that moves and merges their content into the class's docstring, leaving their docstrings empty.
Sphinx renders only the class's docstring, so it won't show a docstring written for ``__init__`` or ``__new__``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Sphinx renders only the class's docstring, so it won't show a docstring written for ``__init__`` or ``__new__``.
Sphinx is configured to render only the class's docstring.
It won't render a docstring written for ``__init__`` or ``__new__``.

@stevepiercy stevepiercy self-assigned this Dec 5, 2026

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.

2 participants