Skip to content

Update Component.__init__ to allow for both Python and Flutter#52

Merged
neriyaco merged 2 commits intomainfrom
binyamin555-patch-1
Jan 31, 2026
Merged

Update Component.__init__ to allow for both Python and Flutter#52
neriyaco merged 2 commits intomainfrom
binyamin555-patch-1

Conversation

@binyamin555
Copy link
Member

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Component.__init__ method to support two calling conventions: the traditional positional children arguments and a new keyword-only children parameter that accepts an Iterable. This change appears to facilitate interoperability between Python and Flutter implementations.

Changes:

  • Added overload import to support multiple type signatures
  • Introduced two overload signatures: one for positional children (*children) and one for keyword-only children (children: Iterable)
  • Modified the __init__ implementation to handle both calling patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def __init__(self, /, *, children: Iterable["ChildType"]) -> None: ...

def __init__(self, *args, children=None) -> None:
self.children = children if children is not None else args
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The implementation has two related issues: (1) Type inconsistency - the children attribute is declared as Tuple["ChildType", ...] (line 8), but when passed as an Iterable via keyword argument, it's assigned directly without conversion to tuple. (2) Codebase convention deviation - the Element class uses tuple(to_iter(children or args)) (element.py:19) to handle children initialization. The Component implementation should follow this same pattern to ensure type safety and consistency across the codebase.

Suggested change
self.children = children if children is not None else args
if children is not None:
self.children = tuple(children)
else:
self.children = tuple(args)

Copilot uses AI. Check for mistakes.
@overload
def __init__(self, *children: "ChildType") -> None: ...
@overload
def __init__(self, /, *, children: Iterable["ChildType"]) -> None: ...
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The second overload signature has a positional-only marker / followed by keyword-only arguments. The / marker with no positional parameters before it is unusual and may be confusing. Consider removing the / marker as it serves no purpose when there are no positional-only parameters to protect. The signature should simply be def __init__(self, *, children: Iterable["ChildType"]) -> None: ...

Suggested change
def __init__(self, /, *, children: Iterable["ChildType"]) -> None: ...
def __init__(self, *, children: Iterable["ChildType"]) -> None: ...

Copilot uses AI. Check for mistakes.
Comment on lines 15 to 16
def __init__(self, *args, children=None) -> None:
self.children = children if children is not None else args
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The new functionality to pass children as a keyword argument (e.g., Component(children=[...])) lacks test coverage. Given that the repository has comprehensive test coverage (as seen in test_html_rendering.py and test_json_rendering.py), tests should be added to verify that the new calling convention works correctly for both the keyword-only children parameter and maintains backward compatibility with the positional children arguments.

Copilot uses AI. Check for mistakes.
@neriyaco neriyaco force-pushed the binyamin555-patch-1 branch from 1306f52 to c5a3014 Compare January 31, 2026 22:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@neriyaco neriyaco merged commit 1d9d108 into main Jan 31, 2026
12 checks passed
@neriyaco neriyaco deleted the binyamin555-patch-1 branch January 31, 2026 22:43
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