Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change type annotation of _add_ws #67

Merged
merged 3 commits into from
Nov 2, 2023
Merged

Change type annotation of _add_ws #67

merged 3 commits into from
Nov 2, 2023

Conversation

wch
Copy link
Collaborator

@wch wch commented Oct 31, 2023

This PR changes the type annotation of _add_ws from bool to TagAttrValue. Even though the value must still actually be a bool, this change simplifies writing functions that pass along kwargs.

For example, previously pyright would flag this as an error, because the kwargs could include _add_ws, but the former is a TagAttrValue while the latter is a bool:

def my_component(*args: TagChild, **kwargs: TagAttrValue) -> Tag:
    return div("Hello", *args, **kwargs)

In order to satisfy the type checker, you previously would have to write this:

def my_component(*args: TagChild, _add_ws: bool: True, **kwargs: TagAttrValue) -> Tag:
    return div("Hello", *args, _add_ws=_add_ws, **kwargs)

After this PR, the first version of the code is not flagged as an error by the type checker. If a non-bool is passed to _add_ws, there will be a run-time error.

@wch wch requested review from schloerke and jcheng5 October 31, 2023 16:32
Copy link
Collaborator

@schloerke schloerke left a comment

Choose a reason for hiding this comment

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

Thank you!

@schloerke schloerke merged commit e245678 into main Nov 2, 2023
16 checks passed
@schloerke schloerke deleted the addws-type branch November 2, 2023 18:20
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