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

improve type hint for OptionalEventCallable #3659

Merged
merged 5 commits into from
Jul 26, 2024
Merged

Conversation

zrr1999
Copy link
Contributor

@zrr1999 zrr1999 commented Jul 17, 2024

Description

The current annotation is only correct for synchronous functions.
I will replace Callable[[ControlEvent], None]] with Callable[[ControlEvent], Union[None, Coroutine[None, None, None]]] to support asynchronous functions.

Test Code

import flet as ft


async def demo(e):
    pass


ft.TextButton("Hello, World!", on_click=demo)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I signed the CLA.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing tests pass locally with my changes
  • I have made corresponding changes to the documentation (if applicable)

Additional details

@ndonkoHenri ndonkoHenri linked an issue Jul 19, 2024 that may be closed by this pull request
1 task
@ndonkoHenri
Copy link
Contributor

Thanks for your contribution! You raised an important point.
I made a commit to further enhance the typing of event-handlers in all the files.

I also considered what the author of #3673 said concerning the return type:

flet probably does not care about the return value, and therefore should not place any restrictions on it.

# Conflicts:
#	sdk/python/packages/flet-core/src/flet_core/canvas/canvas.py
#	sdk/python/packages/flet-core/src/flet_core/charts/pie_chart.py
#	sdk/python/packages/flet-core/src/flet_core/cupertino_alert_dialog.py
#	sdk/python/packages/flet-core/src/flet_core/cupertino_context_menu_action.py
#	sdk/python/packages/flet-core/src/flet_core/cupertino_dialog_action.py
@FeodorFitsner FeodorFitsner merged commit 78ddb4d into flet-dev:main Jul 26, 2024
2 checks passed
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.

Incorrect typing of OptionalEventCallable
3 participants