diff --git a/sdk/python/packages/flet-core/src/flet_core/callable_control.py b/sdk/python/packages/flet-core/src/flet_core/callable_control.py index bd87d4bad..42057b09e 100644 --- a/sdk/python/packages/flet-core/src/flet_core/callable_control.py +++ b/sdk/python/packages/flet-core/src/flet_core/callable_control.py @@ -63,9 +63,9 @@ def _call_method(self, name: str, params: List[str], wait_for_result=True) -> An f"Timeout waiting for {self.__class__.__name__}.{name}({params}) method call" ) result, err = self.__results.pop(evt) - if err != None: + if err is not None: raise Exception(err) - if result == None: + if result is None: return None return json.loads(result) @@ -96,9 +96,9 @@ async def _call_method_async( ) result, err = self.__results.pop(evt) - if err != None: + if err is not None: raise Exception(err) - if result == None: + if result is None: return None return json.loads(result) @@ -106,7 +106,7 @@ def _on_result(self, e): d = json.loads(e.data) result = ControlMethodResults(**d) evt = self.__calls.pop(result.i, None) - if evt == None: + if evt is None: return self.__results[evt] = (result.r, result.e) evt.set() diff --git a/sdk/python/packages/flet-core/src/flet_core/column.py b/sdk/python/packages/flet-core/src/flet_core/column.py index 878a0dba7..b27ceff1e 100644 --- a/sdk/python/packages/flet-core/src/flet_core/column.py +++ b/sdk/python/packages/flet-core/src/flet_core/column.py @@ -227,9 +227,9 @@ def scroll(self, value: Optional[ScrollMode]): self.__set_scroll(value) def __set_scroll(self, value: Optional[ScrollModeString]): - if value == True: + if value is True: value = "auto" - elif value == False: + elif value is False: value = None self._set_attr("scroll", value) diff --git a/sdk/python/packages/flet-core/src/flet_core/container.py b/sdk/python/packages/flet-core/src/flet_core/container.py index 6e793e516..f4040b67d 100644 --- a/sdk/python/packages/flet-core/src/flet_core/container.py +++ b/sdk/python/packages/flet-core/src/flet_core/container.py @@ -35,7 +35,7 @@ try: from typing import Literal -except: +except Exception: from typing_extensions import Literal diff --git a/sdk/python/packages/flet-core/src/flet_core/control.py b/sdk/python/packages/flet-core/src/flet_core/control.py index b43c81168..6d45c79a3 100644 --- a/sdk/python/packages/flet-core/src/flet_core/control.py +++ b/sdk/python/packages/flet-core/src/flet_core/control.py @@ -154,7 +154,7 @@ def __str__(self): attrs = {} for k, v in self.__attrs.items(): attrs[k] = v[0] - return "{} {}".format(self._get_control_name(), attrs) + return f"{self._get_control_name()} {attrs}" # event_handlers @property diff --git a/sdk/python/packages/flet-core/src/flet_core/local_connection.py b/sdk/python/packages/flet-core/src/flet_core/local_connection.py index 89034f9ba..48aebf505 100644 --- a/sdk/python/packages/flet-core/src/flet_core/local_connection.py +++ b/sdk/python/packages/flet-core/src/flet_core/local_connection.py @@ -74,7 +74,7 @@ def _create_update_control_props_handler_arg(self, msg: ClientMessage): ) def _process_command(self, command: Command): - logger.debug("_process_command: {}".format(command)) + logger.debug(f"_process_command: {command}") if command.name == "get": return self._process_get_command(command.values) elif command.name == "add": @@ -89,7 +89,7 @@ def _process_command(self, command: Command): return self._process_invoke_method_command(command.values, command.attrs) elif command.name == "error": return self._process_error_command(command.values) - raise Exception("Unsupported command: {}".format(command.name)) + raise Exception(f"Unsupported command: {command.name}") def _process_add_command(self, command: Command): @@ -131,7 +131,7 @@ def _process_add_command(self, command: Command): id = cmd.attrs.get("id", "") if not id: - id = "_{}".format(self._control_id) + id = f"_{self._control_id}" self._control_id += 1 cmd.attrs["id"] = id diff --git a/sdk/python/packages/flet-core/src/flet_core/locks.py b/sdk/python/packages/flet-core/src/flet_core/locks.py index e0af92ab7..da9e737ca 100644 --- a/sdk/python/packages/flet-core/src/flet_core/locks.py +++ b/sdk/python/packages/flet-core/src/flet_core/locks.py @@ -1,4 +1,4 @@ -class NopeLock(object): +class NopeLock(): def __enter__(self): pass @@ -6,7 +6,7 @@ def __exit__(self, *args): pass -class AsyncNopeLock(object): +class AsyncNopeLock(): async def __aenter__(self): pass diff --git a/sdk/python/packages/flet-core/src/flet_core/page.py b/sdk/python/packages/flet-core/src/flet_core/page.py index 67f30058d..37708d841 100644 --- a/sdk/python/packages/flet-core/src/flet_core/page.py +++ b/sdk/python/packages/flet-core/src/flet_core/page.py @@ -412,7 +412,7 @@ def __validate_controls_page(self, added_controls): for ctrl in added_controls: if ctrl.page and ctrl.page != self: raise Exception( - "Control has already been added to another page: {}".format(ctrl) + f"Control has already been added to another page: {ctrl}" ) def __update_control_ids(self, added_controls, results): @@ -486,7 +486,7 @@ def __on_page_change_event(self, data): self._index[id]._set_attr(name, props[name], dirty=False) def go(self, route, **kwargs): - self.route = route if kwargs == {} else route + self.query.post(kwargs) + self.route = route if not kwargs else route + self.query.post(kwargs) self.__on_route_change.get_sync_handler()( ControlEvent( @@ -501,7 +501,7 @@ def go(self, route, **kwargs): self.query() # Update query url (required when using go) async def go_async(self, route, **kwargs): - self.route = route if kwargs == {} else route + self.query.post(kwargs) + self.route = route if not kwargs else route + self.query.post(kwargs) await self.__on_route_change.get_handler()( ControlEvent( @@ -776,13 +776,13 @@ def __get_launch_url_args( window_height: Optional[int] = None, ): args = {"url": url} - if web_window_name != None: + if web_window_name is not None: args["web_window_name"] = web_window_name - if web_popup_window != None: + if web_popup_window is not None: args["web_popup_window"] = str(web_popup_window) - if window_width != None: + if window_width is not None: args["window_width"] = str(window_width) - if window_height != None: + if window_height is not None: args["window_height"] = str(window_height) return args @@ -845,9 +845,9 @@ def invoke_method( ) result, err = self.__method_call_results.pop(evt) - if err != None: + if err is not None: raise Exception(err) - if result == None: + if result is None: return None return result @@ -889,9 +889,9 @@ async def invoke_method_async( ) result, err = self.__method_call_results.pop(evt) - if err != None: + if err is not None: raise Exception(err) - if result == None: + if result is None: return None return result @@ -899,7 +899,7 @@ def __on_invoke_method_result(self, e): d = json.loads(e.data) result = InvokeMethodResults(**d) evt = self.__method_calls.pop(result.method_id, None) - if evt == None: + if evt is None: return self.__method_call_results[evt] = (result.result, result.error) evt.set() diff --git a/sdk/python/packages/flet-core/src/flet_core/protocol.py b/sdk/python/packages/flet-core/src/flet_core/protocol.py index d7b0ee2a5..39db09943 100644 --- a/sdk/python/packages/flet-core/src/flet_core/protocol.py +++ b/sdk/python/packages/flet-core/src/flet_core/protocol.py @@ -44,7 +44,7 @@ class Command: commands: List[Any] = field(default_factory=list) def __str__(self): - return "{} {} {}".format(self.name, self.values, self.attrs) + return f"{self.name} {self.values} {self.attrs}" @dataclass diff --git a/sdk/python/packages/flet-core/src/flet_core/querystring.py b/sdk/python/packages/flet-core/src/flet_core/querystring.py index 53d67d571..5fb91fa4d 100644 --- a/sdk/python/packages/flet-core/src/flet_core/querystring.py +++ b/sdk/python/packages/flet-core/src/flet_core/querystring.py @@ -28,12 +28,10 @@ def _is_encoded(self) -> bool: if "?" in self.url: q_result = self._querystring_part() return ( - True - if self._decode_url_component( + self._decode_url_component( self.url[q_result.start() + 1 : q_result.end()] ) != self.url[q_result.start() + 1 : q_result.end()] - else False ) def _querystring_part(self, url_string: bool = False): diff --git a/sdk/python/packages/flet-core/src/flet_core/row.py b/sdk/python/packages/flet-core/src/flet_core/row.py index 820bd6c78..8057bc58c 100644 --- a/sdk/python/packages/flet-core/src/flet_core/row.py +++ b/sdk/python/packages/flet-core/src/flet_core/row.py @@ -230,9 +230,9 @@ def scroll(self, value: Optional[ScrollMode]): self.__set_scroll(value) def __set_scroll(self, value: Optional[ScrollModeString]): - if value == True: + if value is True: value = "auto" - elif value == False: + elif value is False: value = None self._set_attr("scroll", value) diff --git a/sdk/python/packages/flet-core/src/flet_core/view.py b/sdk/python/packages/flet-core/src/flet_core/view.py index cd8411d85..9bfb94eb0 100644 --- a/sdk/python/packages/flet-core/src/flet_core/view.py +++ b/sdk/python/packages/flet-core/src/flet_core/view.py @@ -193,9 +193,9 @@ def scroll(self, value: Optional[ScrollMode]): self.__set_scroll(value) def __set_scroll(self, value: Optional[ScrollModeString]): - if value == True: + if value is True: value = "auto" - elif value == False: + elif value is False: value = None self._set_attr("scroll", value) diff --git a/sdk/python/packages/flet-core/tests/test_alert_dialog.py b/sdk/python/packages/flet-core/tests/test_alert_dialog.py index cad3730b2..855360d70 100644 --- a/sdk/python/packages/flet-core/tests/test_alert_dialog.py +++ b/sdk/python/packages/flet-core/tests/test_alert_dialog.py @@ -32,4 +32,3 @@ def test_alignment_str(): assert isinstance(r._get_attr("actionsalignment"), str) cmd = r._build_add_commands() assert cmd[0].attrs["actionsalignment"] == "center" - diff --git a/sdk/python/packages/flet-core/tests/test_animated_switcher.py b/sdk/python/packages/flet-core/tests/test_animated_switcher.py index 487bccc1b..9f4cc2b1a 100644 --- a/sdk/python/packages/flet-core/tests/test_animated_switcher.py +++ b/sdk/python/packages/flet-core/tests/test_animated_switcher.py @@ -19,7 +19,7 @@ def test_instance_no_attrs_set(): def test_switch_in_curve_enum(): r = ft.AnimatedSwitcher() - assert r.switch_in_curve == None + assert r.switch_in_curve is None assert r._get_attr("switchInCurve") is None r = ft.AnimatedSwitcher(switch_in_curve=ft.AnimationCurve.BOUNCE_IN) @@ -34,7 +34,7 @@ def test_switch_in_curve_enum(): def test_switch_out_curve_enum(): r = ft.AnimatedSwitcher() - assert r.switch_out_curve == None + assert r.switch_out_curve is None assert r._get_attr("switchOutCurve") is None r = ft.AnimatedSwitcher(switch_out_curve=ft.AnimationCurve.BOUNCE_IN) @@ -49,7 +49,7 @@ def test_switch_out_curve_enum(): def test_transition_enum(): r = ft.AnimatedSwitcher() - assert r.transition == None + assert r.transition is None assert r._get_attr("transition") is None r = ft.AnimatedSwitcher(transition=ft.AnimatedSwitcherTransition.FADE) diff --git a/sdk/python/packages/flet-core/tests/test_text.py b/sdk/python/packages/flet-core/tests/test_text.py index 0056961ad..112f9ed14 100644 --- a/sdk/python/packages/flet-core/tests/test_text.py +++ b/sdk/python/packages/flet-core/tests/test_text.py @@ -34,7 +34,7 @@ def test_text_align_enum(): def test_text_style_enum(): r = ft.Text() - assert r.style == None + assert r.style is None assert r._get_attr("style") is None r = ft.Text(style=ft.TextThemeStyle.DISPLAY_LARGE) @@ -64,7 +64,7 @@ def test_text_overflow_enum(): def test_weight_enum(): r = ft.Text() - assert r.weight == None + assert r.weight is None assert r._get_attr("weight") is None r = ft.Text(weight=ft.FontWeight.BOLD) diff --git a/sdk/python/packages/flet-pyodide/src/flet/pyodide_connection.py b/sdk/python/packages/flet-pyodide/src/flet/pyodide_connection.py index 0a601e26a..9eb08153b 100644 --- a/sdk/python/packages/flet-pyodide/src/flet/pyodide_connection.py +++ b/sdk/python/packages/flet-pyodide/src/flet/pyodide_connection.py @@ -77,7 +77,7 @@ async def __on_message(self, data: str): ) else: # it's something else - raise Exception('Unknown message "{}": {}'.format(msg.action, msg.payload)) + raise Exception(f'Unknown message "{msg.action}": {msg.payload}') async def send_command_async(self, session_id: str, command: Command): return self.send_command(session_id, command) diff --git a/sdk/python/packages/flet/src/flet/__pyinstaller/win_utils.py b/sdk/python/packages/flet/src/flet/__pyinstaller/win_utils.py index 578254826..bbc8e0954 100644 --- a/sdk/python/packages/flet/src/flet/__pyinstaller/win_utils.py +++ b/sdk/python/packages/flet/src/flet/__pyinstaller/win_utils.py @@ -3,9 +3,9 @@ import uuid from pathlib import Path -import packaging.version as version +from packaging import version import pefile -import PyInstaller.utils.win32.versioninfo as versioninfo +from PyInstaller.utils.win32 import versioninfo from PyInstaller.building.icon import normalize_icon_type from PyInstaller.compat import win32api from PyInstaller.utils.win32.icon import IconFile, normalize_icon_type diff --git a/sdk/python/packages/flet/src/flet/async_local_socket_connection.py b/sdk/python/packages/flet/src/flet/async_local_socket_connection.py index f781ce877..ef251f516 100644 --- a/sdk/python/packages/flet/src/flet/async_local_socket_connection.py +++ b/sdk/python/packages/flet/src/flet/async_local_socket_connection.py @@ -75,7 +75,7 @@ async def __receive_loop(self, reader: asyncio.StreamReader): while True: try: raw_msglen = await reader.readexactly(4) - except: + except Exception: return None if not raw_msglen: @@ -93,8 +93,8 @@ async def __send_loop(self, writer: asyncio.StreamWriter): msg = struct.pack(">I", len(data)) + data writer.write(msg) # await writer.drain() - logger.debug("sent to TCP: {}".format(len(msg))) - except: + logger.debug(f"sent to TCP: {len(msg)}") + except Exception: # re-enqueue the message to repeat it when re-connected self.__send_queue.put_nowait(message) raise @@ -128,7 +128,7 @@ async def __on_message(self, data: str): ) else: # it's something else - raise Exception('Unknown message "{}": {}'.format(msg.action, msg.payload)) + raise Exception(f'Unknown message "{msg.action}": {msg.payload}') async def send_command_async(self, session_id: str, command: Command): result, message = self._process_command(command) diff --git a/sdk/python/packages/flet/src/flet/async_websocket_connection.py b/sdk/python/packages/flet/src/flet/async_websocket_connection.py index f4271fec5..72ac5aae6 100644 --- a/sdk/python/packages/flet/src/flet/async_websocket_connection.py +++ b/sdk/python/packages/flet/src/flet/async_websocket_connection.py @@ -114,7 +114,7 @@ async def __start_loops(self): # re-connect if one of tasks failed if failed: - logger.debug(f"Re-connecting to Flet server in 1 second") + logger.debug("Re-connecting to Flet server in 1 second") await asyncio.sleep(self.__CONNECT_TIMEOUT) await self.connect() @@ -148,7 +148,7 @@ async def __send_loop(self): message = await self.__send_queue.get() try: await self.__ws.send(message) - except: + except Exception: # re-enqueue the message to repeat it when re-connected self.__send_queue.put_nowait(message) raise @@ -195,5 +195,5 @@ async def close(self): if self.__ws: try: await self.__ws.close() - except: + except Exception: pass # do nothing diff --git a/sdk/python/packages/flet/src/flet/auth/authorization.py b/sdk/python/packages/flet/src/flet/auth/authorization.py index 101e800b8..f18c4e7ad 100644 --- a/sdk/python/packages/flet/src/flet/auth/authorization.py +++ b/sdk/python/packages/flet/src/flet/auth/authorization.py @@ -117,13 +117,13 @@ def __fetch_user_and_groups(self): assert self.__token is not None if self.fetch_user: self.user = self.provider._fetch_user(self.__token.access_token) - if self.user == None and self.provider.user_endpoint != None: - if self.provider.user_id_fn == None: + if self.user is None and self.provider.user_endpoint is not None: + if self.provider.user_id_fn is None: raise Exception( "user_id_fn must be specified too if user_endpoint is not None" ) self.user = self.__get_user() - if self.fetch_groups and self.user != None: + if self.fetch_groups and self.user is not None: self.user.groups = self.provider._fetch_groups( self.__token.access_token ) @@ -132,13 +132,13 @@ async def __fetch_user_and_groups_async(self): assert self.__token is not None if self.fetch_user: self.user = await self.provider._fetch_user_async(self.__token.access_token) - if self.user == None and self.provider.user_endpoint != None: - if self.provider.user_id_fn == None: + if self.user is None and self.provider.user_endpoint is not None: + if self.provider.user_id_fn is None: raise Exception( "user_id_fn must be specified too if user_endpoint is not None" ) self.user = await self.__get_user_async() - if self.fetch_groups and self.user != None: + if self.fetch_groups and self.user is not None: self.user.groups = await self.provider._fetch_groups_async( self.__token.access_token ) @@ -195,7 +195,7 @@ def __complete_refresh_token_request(self, refresh_resp): assert self.__token is not None client = WebApplicationClient(self.provider.client_id) t = client.parse_request_body_response(refresh_resp.text) - if t.get("refresh_token") == None: + if t.get("refresh_token") is None: t["refresh_token"] = self.__token.refresh_token self.__token = self.__convert_token(t) @@ -215,7 +215,7 @@ def __get_user_request(self): assert self.token is not None assert self.provider.user_endpoint is not None headers = self.__get_default_headers() - headers["Authorization"] = "Bearer {}".format(self.token.access_token) + headers["Authorization"] = f"Bearer {self.token.access_token}" return httpx.Request("GET", self.provider.user_endpoint, headers=headers) def __complete_user_request(self, user_resp): @@ -226,5 +226,5 @@ def __complete_user_request(self, user_resp): def __get_default_headers(self): return { - "User-Agent": "Flet/{}".format(version), + "User-Agent": f"Flet/{version}", } diff --git a/sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py b/sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py index ad3083ad1..5eb140f6a 100644 --- a/sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py +++ b/sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py @@ -93,6 +93,6 @@ def __complete_fetch_user_details(self, user_resp, emails_resp): def __get_client_headers(self, access_token): return { - "Authorization": "Bearer {}".format(access_token), - "User-Agent": "Flet/{}".format(version), + "Authorization": f"Bearer {access_token}", + "User-Agent": f"Flet/{version}", } diff --git a/sdk/python/packages/flet/src/flet/cli/commands/pack.py b/sdk/python/packages/flet/src/flet/cli/commands/pack.py index f86e17533..0f85ad348 100644 --- a/sdk/python/packages/flet/src/flet/cli/commands/pack.py +++ b/sdk/python/packages/flet/src/flet/cli/commands/pack.py @@ -1,5 +1,6 @@ import argparse import os +import sys import shutil from pathlib import Path @@ -126,7 +127,7 @@ def handle(self, options: argparse.Namespace) -> None: if options.onedir: if is_macos(): print("--onedir options is not supported on macOS.") - exit(1) + sys.exit(1) pyi_args.append("--onedir") else: pyi_args.append("--onefile") @@ -221,4 +222,4 @@ def handle(self, options: argparse.Namespace) -> None: shutil.rmtree(hook_config.temp_bin_dir, ignore_errors=True) except ImportError as e: print("Please install PyInstaller module to use flet pack command:", e) - exit(1) + sys.exit(1) diff --git a/sdk/python/packages/flet/src/flet/cli/commands/publish.py b/sdk/python/packages/flet/src/flet/cli/commands/publish.py index c61f00636..54337c470 100644 --- a/sdk/python/packages/flet/src/flet/cli/commands/publish.py +++ b/sdk/python/packages/flet/src/flet/cli/commands/publish.py @@ -1,6 +1,7 @@ import argparse import json import os +import sys import re import shutil import tarfile @@ -97,7 +98,7 @@ def handle(self, options: argparse.Namespace) -> None: if not Path(script_path).exists(): print(f"File not found: {script_path}") - exit(1) + sys.exit(1) script_dir = os.path.dirname(script_path) @@ -118,7 +119,7 @@ def handle(self, options: argparse.Namespace) -> None: web_path = get_package_web_dir() if not os.path.exists(web_path): print("Flet module does not contain 'web' directory.") - exit(1) + sys.exit(1) copy_tree(web_path, dist_dir) # copy assets @@ -130,7 +131,7 @@ def handle(self, options: argparse.Namespace) -> None: if assets_dir: if not os.path.exists(assets_dir): print("Assets dir not found:", assets_dir) - exit(1) + sys.exit(1) copy_tree(assets_dir, dist_dir) # create "./dist/requirements.txt" if not exist @@ -153,7 +154,7 @@ def handle(self, options: argparse.Namespace) -> None: pyodide_dep_found = True break if not pyodide_dep_found: - deps.append(f"flet-pyodide") + deps.append("flet-pyodide") temp_reqs_txt = Path(tempfile.gettempdir()).joinpath(random_string(10)) with open(temp_reqs_txt, "w") as f: diff --git a/sdk/python/packages/flet/src/flet/cli/commands/run.py b/sdk/python/packages/flet/src/flet/cli/commands/run.py index 45e39818c..7b45f1edb 100644 --- a/sdk/python/packages/flet/src/flet/cli/commands/run.py +++ b/sdk/python/packages/flet/src/flet/cli/commands/run.py @@ -80,7 +80,7 @@ def handle(self, options: argparse.Namespace) -> None: if not Path(script_path).exists(): print(f"File not found: {script_path}") - exit(1) + sys.exit(1) script_dir = os.path.dirname(script_path) diff --git a/sdk/python/packages/flet/src/flet/flet.py b/sdk/python/packages/flet/src/flet/flet.py index ad1086be1..591f33049 100644 --- a/sdk/python/packages/flet/src/flet/flet.py +++ b/sdk/python/packages/flet/src/flet/flet.py @@ -249,7 +249,7 @@ def close_flet_view(pid_file): fvp_pid = int(f.read()) logger.debug(f"Flet View process {fvp_pid}") os.kill(fvp_pid, signal.SIGKILL) - except: + except Exception: pass finally: os.remove(pid_file) @@ -434,7 +434,7 @@ def __start_flet_server( # download flet from GitHub (python module developer mode) fletd_path = __download_fletd() else: - logger.info(f"Flet Server found in PATH") + logger.info("Flet Server found in PATH") fletd_env = {**os.environ} @@ -464,7 +464,7 @@ def __start_flet_server( web_root_dir = get_package_web_dir() if not os.path.exists(web_root_dir): - raise Exception("Web root path not found: {}".format(web_root_dir)) + raise Exception(f"Web root path not found: {web_root_dir}") args = [fletd_path, "--content-dir", web_root_dir, "--port", str(port)] @@ -540,7 +540,7 @@ def __get_assets_dir_path(assets_dir: Optional[str]): def __locate_and_unpack_flet_view(page_url, assets_dir, hidden): - logger.info(f"Starting Flet View app...") + logger.info("Starting Flet View app...") args = [] diff --git a/sdk/python/packages/flet/src/flet/reconnecting_websocket.py b/sdk/python/packages/flet/src/flet/reconnecting_websocket.py index 694b17ecd..ccd9d4e34 100644 --- a/sdk/python/packages/flet/src/flet/reconnecting_websocket.py +++ b/sdk/python/packages/flet/src/flet/reconnecting_websocket.py @@ -65,10 +65,10 @@ def _connect_loop(self): else _REMOTE_CONNECT_TIMEOUT_SEC ) r = self.wsapp.run_forever() - logger.debug(f"Exited run_forever()") + logger.debug("Exited run_forever()") websocket.setdefaulttimeout(self.default_timeout) self.connected.clear() - if r != True: + if r is not True: return if self.retry == 0 and self._on_failed_connect_handler is not None: diff --git a/sdk/python/packages/flet/src/flet/sync_local_socket_connection.py b/sdk/python/packages/flet/src/flet/sync_local_socket_connection.py index 8c046ba1a..bcc6ac072 100644 --- a/sdk/python/packages/flet/src/flet/sync_local_socket_connection.py +++ b/sdk/python/packages/flet/src/flet/sync_local_socket_connection.py @@ -106,7 +106,7 @@ def __on_message(self, data): th.start() else: # it's something else - raise Exception('Unknown message "{}": {}'.format(msg.action, msg.payload)) + raise Exception(f'Unknown message "{msg.action}": {msg.payload}') def send_command(self, session_id: str, command: Command): result, message = self._process_command(command) @@ -164,9 +164,9 @@ def __send_msg(self, sock, msg): msg = struct.pack(">I", len(msg)) + msg try: sock.sendall(msg) - logger.debug("Sent: {}".format(len(msg))) + logger.debug(f"Sent: {len(msg)}") except Exception as e: - logger.debug("Error sending a message over a socket: {}".format(e)) + logger.debug(f"Error sending a message over a socket: {e}") def __recv_msg(self, sock): # Read message length and unpack it into an integer @@ -174,7 +174,7 @@ def __recv_msg(self, sock): if not raw_msglen: return None msglen = struct.unpack(">I", raw_msglen)[0] - logger.debug("Message size: {}".format(msglen)) + logger.debug(f"Message size: {msglen}") # Read the message data return self.__recvall(sock, msglen) @@ -184,7 +184,7 @@ def __recvall(self, sock, n): while len(data) < n: try: packet = sock.recv(n - len(data)) - except: + except Exception: return None # print("packet received:", len(packet)) if not packet: diff --git a/sdk/python/patch_toml.py b/sdk/python/patch_toml.py index 630f6534a..e6a0b5406 100644 --- a/sdk/python/patch_toml.py +++ b/sdk/python/patch_toml.py @@ -11,7 +11,7 @@ current_dir = pathlib.Path(os.getcwd()) toml_path = current_dir.joinpath(current_dir, sys.argv[1]) ver = sys.argv[2] -print("Patching TOML file {} to {}".format(toml_path, ver)) +print(f"Patching TOML file {toml_path} to {ver}") # read with open(toml_path, "r") as f: