Skip to content

Modernize typing syntax in entity and platform doc examples#3199

Open
frenck wants to merge 1 commit into
masterfrom
frenck/modernize-typing-syntax
Open

Modernize typing syntax in entity and platform doc examples#3199
frenck wants to merge 1 commit into
masterfrom
frenck/modernize-typing-syntax

Conversation

@frenck

@frenck frenck commented Jun 19, 2026

Copy link
Copy Markdown
Member

Proposed change

A few entity and platform documentation examples still used the legacy typing syntax (Optional[...] and typing.Iterable). This updates them to the modern syntax that Home Assistant uses: PEP 604 unions (X | None) and collections.abc for the abstract base classes.

  • fan.md: percentage properties and the turn_on / async_turn_on signatures (the latter split to one argument per line).
  • conversation.md: the conversation_id type in the ConversationInput table.
  • reproduce_state.md: the import line and the context parameter.

Type of change

  • Document existing features within Home Assistant
  • Document new or changing features for which there is an existing pull request elsewhere
  • Spelling or grammatical corrections, or rewording for improved clarity
  • Editing or restructuring documentation guidelines
  • Changes to the backend of this documentation
  • Remove stale or deprecated documentation

Checklist

  • I have read and followed the documentation guidelines.
  • I have verified that my changes render correctly in the documentation.

Additional information

  • This PR fixes or closes issue: fixes #
  • Link to relevant existing code or pull request:

Summary by CodeRabbit

  • Documentation
    • Updated type annotations across core entity and platform documentation to use modern Python typing syntax (e.g., str | None instead of Optional[str]).
    • Reformatted code examples and method signatures for improved readability.

@frenck frenck added the enhancement New feature or request label Jun 19, 2026
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Documentation code examples in conversation.md, fan.md, and reproduce_state.md are updated to replace Optional[X] type annotations with modern Python X | None union syntax. The fan.md method signatures are also reformatted to multi-line form, and reproduce_state.md switches Iterable to import from collections.abc.

Changes

Type annotation modernization in docs examples

Layer / File(s) Summary
Type annotation updates across conversation, fan, and reproduce_state docs
docs/core/entity/conversation.md, docs/core/entity/fan.md, docs/core/platform/reproduce_state.md
conversation_id type changed to `str

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • silamon
  • justanotherariel
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: modernizing typing syntax in documentation examples across multiple files.
Description check ✅ Passed The description follows the template structure, includes a clear proposed change section, properly selects the type of change, completes the checklist, and provides relevant details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch frenck/modernize-typing-syntax

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/core/entity/fan.md`:
- Around line 155-172: The code example for the `turn_on` and `async_turn_on`
method signatures uses the `Any` type annotation in the `**kwargs: Any`
parameter, but the documentation does not show where `Any` is imported from. Add
either an import statement at the beginning of the code example showing `from
typing import Any`, or add a clarifying note in the documentation text
explaining that `Any` must be imported from the `typing` module (or from
`builtins` in Python 3.11+).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bdb2d640-a8f2-423b-8f09-a06b6978f5c8

📥 Commits

Reviewing files that changed from the base of the PR and between 8f2e306 and aaf509c.

📒 Files selected for processing (3)
  • docs/core/entity/conversation.md
  • docs/core/entity/fan.md
  • docs/core/platform/reproduce_state.md

Comment thread docs/core/entity/fan.md
Comment thread docs/core/entity/fan.md
# Implement one of these methods.

def turn_on(self, speed: Optional[str] = None, percentage: Optional[int] = None, preset_mode: Optional[str] = None, **kwargs: Any) -> None:
def turn_on(

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.

the signature seems to be different - there is no speed argument in the original FanEnity

https://github.com/home-assistant/core/blob/3c7774d9b8cb2dc872855c316539c4772a1e2320/homeassistant/components/fan/__init__.py#L291-L298

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants