fixed types annotations for meta in add_page() to accept components #6012
+7
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All Submissions:
Type of change
New Feature Submission:
Changes To Core Features:
Description
Updated type annotations for the
metaparameter to acceptComponentin addition todict[str, str], making the typing more accurate and flexible.Previous PR added support for adding any components as meta to add_page() but the type has was not changed. This PR modifies the changes.
Changes:
metatype fromSequence[Mapping[str, str]]toSequence[Mapping[str, str] | Component]inUnevaluatedPagedataclass andadd_page()methodmetaparameter type inadd_meta()function fromlist[dict]tolist[Mapping[str, Any] | Component]Why:
The existing type annotations were too restrictive. The
metaparameter can acceptComponentobjects (for link components, script tags, etc.), not just dictionaries. This change aligns the type hints with the actual runtime behavior.Personally, my OCRs triggered when meta links in add_page() triggered a type error. It is a small PR for some peace of mind. Thanks for the fantastic framework. I am having a lot of fun with it.
Testing:
pyright)ruff)