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

run io_bound and cpu_bound maintain type signatures of their callbacks #2733

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

petergaultney
Copy link
Contributor

This is a pretty simple way for nicegui to not 'drop' the types of callbacks that need to get run in the background for whatever reason. I know mypy supports this, and I'm pretty sure other type checkers do too. It's an official part of the type system.

For this code:

Screenshot 2024-03-20 at 11 08 40 AM

we go from

Screenshot 2024-03-20 at 11 09 13 AM

to

Screenshot 2024-03-20 at 11 10 00 AM

And (although i have no accompanying screenshots) you would also get type checking on your inputs to the function.

nicegui/run.py Outdated Show resolved Hide resolved
Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

Thanks for this pull request, @petergaultney! I really like filling these gaps of missing type annotations.

Just one remark: I would prefer explicitly ignoring the mypy warning (# type: ignore) instead of casting it to R, creating a "lie". What do you think?

@falkoschindler falkoschindler added this to the 1.4.20 milestone Mar 22, 2024
@falkoschindler falkoschindler added the enhancement New feature or request label Mar 22, 2024
@petergaultney
Copy link
Contributor Author

petergaultney commented Mar 22, 2024

Thanks for this pull request, @petergaultney! I really like filling these gaps of missing type annotations.

Just one remark: I would prefer explicitly ignoring the mypy warning (# type: ignore) instead of casting it to R, creating a "lie". What do you think?

I think the outer return type R is still a lie in a sense - ignore and cast both let us violate the type system. But I can see how ignore might seem a little less confusing to readers of this code. I'll change that over.

Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

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

Thanks again, @petergaultney!
Let's merge! 🚀

@falkoschindler falkoschindler merged commit 24cbe9b into zauberzeug:main Mar 22, 2024
1 check passed
@petergaultney petergaultney deleted the types/run-functions branch April 1, 2024 20:17
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.

None yet

2 participants