Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/python/packages/flet-web/src/flet_web/fastapi/flet_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def __on_session_created(self):
_context_page.set(self.__session.page)
context.reset_auto_update()

if asyncio.iscoroutinefunction(self.__main):
if inspect.iscoroutinefunction(self.__main):
await self.__main(self.__session.page)

elif inspect.isasyncgenfunction(self.__main):
Expand Down Expand Up @@ -260,7 +260,7 @@ async def __on_message(self, data: Any):

# run before_main
try:
if asyncio.iscoroutinefunction(self.__before_main):
if inspect.iscoroutinefunction(self.__before_main):
await self.__before_main(self.__session.page)
elif callable(self.__before_main):
self.__before_main(self.__session.page)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
from collections.abc import Awaitable, Coroutine, Sequence
from contextlib import asynccontextmanager, suppress
from typing import (
Expand Down Expand Up @@ -74,7 +75,7 @@ async def lifespan(app: fastapi.FastAPI):
await flet_web.fastapi.app_manager.start()
if on_startup:
for h in on_startup:
if asyncio.iscoroutinefunction(h):
if inspect.iscoroutinefunction(h):
await h()
else:
h()
Expand All @@ -83,7 +84,7 @@ async def lifespan(app: fastapi.FastAPI):
yield
if on_shutdown:
for h in on_shutdown:
if asyncio.iscoroutinefunction(h):
if inspect.iscoroutinefunction(h):
await h()
else:
h()
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet/src/flet/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async def on_session_created(session: Session):
assert main is not None
_context_page.set(session.page)
context.reset_auto_update()
if asyncio.iscoroutinefunction(main):
if inspect.iscoroutinefunction(main):
await main(session.page)

elif inspect.isasyncgenfunction(main):
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet/src/flet/controls/base_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ async def _trigger_event(self, event_name: str, event_data: Any):

# Handle async and sync event handlers accordingly
event_handler = getattr(self, field_name)
if asyncio.iscoroutinefunction(event_handler):
if inspect.iscoroutinefunction(event_handler):
if get_param_count(event_handler) == 0:
await event_handler()
else:
Expand Down
9 changes: 5 additions & 4 deletions sdk/python/packages/flet/src/flet/controls/page.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import logging
import sys
import threading
Expand Down Expand Up @@ -486,7 +487,7 @@ def run_task(
current page.
"""
_context_page.set(self)
if not asyncio.iscoroutinefunction(handler):
if not inspect.iscoroutinefunction(handler):
raise TypeError("handler must be a coroutine function")

future = asyncio.run_coroutine_threadsafe(
Expand Down Expand Up @@ -697,7 +698,7 @@ async def login(

e = LoginEvent(name="login", control=self, error="", error_description="")
if self.on_login:
if asyncio.iscoroutinefunction(self.on_login):
if inspect.iscoroutinefunction(self.on_login):
asyncio.create_task(self.on_login(e))
elif callable(self.on_login):
self.on_login(e)
Expand Down Expand Up @@ -732,7 +733,7 @@ async def _authorize_callback(self, data: dict[str, Optional[str]]) -> None:
except Exception as ex:
e.error = str(ex)
if self.on_login:
if asyncio.iscoroutinefunction(self.on_login):
if inspect.iscoroutinefunction(self.on_login):
asyncio.create_task(self.on_login(e))
elif callable(self.on_login):
self.on_login(e)
Expand All @@ -746,7 +747,7 @@ def logout(self) -> None:
self.__authorization = None
e = ControlEvent(name="logout", control=self)
if self.on_logout:
if asyncio.iscoroutinefunction(self.on_logout):
if inspect.iscoroutinefunction(self.on_logout):
asyncio.create_task(self.on_logout(e))
elif callable(self.on_logout):
self.on_logout(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import contextlib
import inspect
import logging
import os
import tempfile
Expand Down Expand Up @@ -250,7 +251,7 @@ async def __on_message(self, data: Any):

register_error = ""
try:
if asyncio.iscoroutinefunction(self.__before_main):
if inspect.iscoroutinefunction(self.__before_main):
await self.__before_main(self.session.page)
elif callable(self.__before_main):
self.__before_main(self.session.page)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import logging
import traceback
from typing import Any
Expand Down Expand Up @@ -69,7 +70,7 @@ async def __on_message(self, data: Any):

register_error = ""
try:
if asyncio.iscoroutinefunction(self.__before_main):
if inspect.iscoroutinefunction(self.__before_main):
await self.__before_main(self.session.page)
elif callable(self.__before_main):
self.__before_main(self.session.page)
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet/src/flet/messaging/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import logging
import traceback
import weakref
Expand Down Expand Up @@ -351,15 +352,15 @@ async def __updates_scheduler(self):
if hook and hook.setup and not is_cleanup:
hook.cancel()
res = None
if asyncio.iscoroutinefunction(hook.setup):
if inspect.iscoroutinefunction(hook.setup):
hook._setup_task = asyncio.create_task(hook.setup())
else:
res = hook.setup()
if callable(res):
hook.cleanup = res
elif hook and hook.cleanup and is_cleanup:
hook.cancel()
if asyncio.iscoroutinefunction(hook.cleanup):
if inspect.iscoroutinefunction(hook.cleanup):
hook._cleanup_task = asyncio.create_task(hook.cleanup())
else:
hook.cleanup()
Expand Down
3 changes: 2 additions & 1 deletion sdk/python/packages/flet/src/flet/pubsub/pubsub_hub.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import logging
import threading
from collections.abc import Awaitable, Iterable
Expand Down Expand Up @@ -150,7 +151,7 @@ def __send(
if not self.__loop:
raise RuntimeError("PubSub event loop is not set")

if asyncio.iscoroutinefunction(handler):
if inspect.iscoroutinefunction(handler):
asyncio.run_coroutine_threadsafe(handler(*args), self.__loop)
else:
if self.__executor:
Expand Down
3 changes: 2 additions & 1 deletion sdk/python/packages/flet/src/flet/testing/flet_test_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect
import logging
import os
import platform
Expand Down Expand Up @@ -195,7 +196,7 @@ async def main(page: ft.Page):
page.theme_mode = ft.ThemeMode.LIGHT
page.update()

if asyncio.iscoroutinefunction(self.__flet_app_main):
if inspect.iscoroutinefunction(self.__flet_app_main):
await self.__flet_app_main(page)
elif callable(self.__flet_app_main):
self.__flet_app_main(page)
Expand Down