Browse Source

more Python <3.9 compatibility

Falko Schindler 3 năm trước cách đây
mục cha
commit
091bb5a4eb

+ 1 - 1
nicegui/config.py

@@ -34,7 +34,7 @@ try:
     with open(filepath) as f:
         source = f.read()
 except FileNotFoundError:
-    print('Could not main script. Starting with interactive mode.', flush=True)
+    print('Could not find main script. Starting with interactive mode.', flush=True)
     config = Config(interactive=True)
 else:
     for node in ast.walk(ast.parse(source)):

+ 3 - 3
nicegui/elements/choice_element.py

@@ -1,17 +1,17 @@
 import justpy as jp
-from typing import Any, Awaitable, Callable, Optional, Union
+from typing import Any, Awaitable, Callable, Dict, List, Optional, Union
 from .value_element import ValueElement
 
 class ChoiceElement(ValueElement):
 
     def __init__(self,
                  view: jp.HTMLBaseComponent,
-                 options: Union[list, dict],
+                 options: Union[List, Dict],
                  *,
                  value: Any,
                  on_change: Optional[Union[Callable, Awaitable]] = None,
                  ):
-        if isinstance(options, list):
+        if isinstance(options, List):
             view.options = [{'label': option, 'value': option} for option in options]
         else:
             view.options = [{'label': value, 'value': key} for key, value in options.items()]

+ 2 - 1
nicegui/elements/group.py

@@ -1,4 +1,5 @@
 from __future__ import annotations
+from typing import List
 import justpy as jp
 from ..globals import view_stack
 from ..binding import active_links, bindings, bindable_properties
@@ -17,7 +18,7 @@ class Group(Element):
         return self.classes(replace='').style(replace='')
 
     def clear(self):
-        def collect_components(view: jp.HTMLBaseComponent) -> list[jp.HTMLBaseComponent]:
+        def collect_components(view: jp.HTMLBaseComponent) -> List[jp.HTMLBaseComponent]:
             return view.components + [view for child in view.components for view in collect_components(child)]
         components = collect_components(self.view)
 

+ 2 - 2
nicegui/elements/joystick.py

@@ -1,4 +1,4 @@
-from typing import Callable, Optional
+from typing import Callable, Dict, Optional
 from .custom_view import CustomView
 from .element import Element
 
@@ -43,7 +43,7 @@ class Joystick(Element):
                  on_start: Optional[Callable] = None,
                  on_move: Optional[Callable] = None,
                  on_end: Optional[Callable] = None,
-                 **options: dict,
+                 **options: Dict,
                  ):
         """Joystick
 

+ 2 - 2
nicegui/elements/keyboard.py

@@ -1,5 +1,5 @@
 import traceback
-from typing import Awaitable, Callable, Optional, Union
+from typing import Awaitable, Callable, Dict, Optional, Union
 
 from ..events import KeyEventArguments, KeyboardAction, KeyboardKey, KeyboardModifiers, handle_event
 from .custom_view import CustomView
@@ -35,7 +35,7 @@ class Keyboard(Element):
         self.active = active
         self.key_handler = on_key
 
-    def handle_key(self, msg: dict):
+    def handle_key(self, msg: Dict):
         if not self.active:
             return
 

+ 2 - 1
nicegui/elements/log.py

@@ -1,4 +1,5 @@
 from __future__ import annotations
+from typing import Deque
 import asyncio
 import traceback
 import urllib
@@ -9,7 +10,7 @@ from .element import Element
 
 class LogView(CustomView):
 
-    def __init__(self, lines: deque[str], max_lines: int):
+    def __init__(self, lines: Deque[str], max_lines: int):
         super().__init__('log', __file__, max_lines=max_lines)
         self.lines = lines
         self.allowed_events = ['onConnect']

+ 2 - 2
nicegui/elements/radio.py

@@ -1,11 +1,11 @@
 import justpy as jp
-from typing import Awaitable, Callable, Optional, Union
+from typing import Awaitable, Callable, Dict, List, Optional, Union
 from .choice_element import ChoiceElement
 
 class Radio(ChoiceElement):
 
     def __init__(self,
-                 options: Union[list, dict],
+                 options: Union[List, Dict],
                  *,
                  value: any = None,
                  on_change: Optional[Union[Callable, Awaitable]] = None,

+ 3 - 3
nicegui/elements/scene_object3d.py

@@ -1,12 +1,12 @@
 from __future__ import annotations
 import asyncio
-from typing import Optional
+from typing import List, Optional
 import uuid
 import numpy as np
 from justpy.htmlcomponents import WebPage
 
 class Object3D:
-    stack: list[Object3D] = []
+    stack: List[Object3D] = []
 
     def __init__(self, type: str, *args):
         self.type = type
@@ -96,7 +96,7 @@ class Object3D:
         Rz = np.array([[np.cos(kappa), -np.sin(kappa), 0], [np.sin(kappa), np.cos(kappa), 0], [0, 0, 1]])
         return self.rotate_R((Rz @ Ry @ Rx).tolist())
 
-    def rotate_R(self, R: list[list[float]]):
+    def rotate_R(self, R: List[List[float]]):
         if self.R != R:
             self.R = R
             self.run_command(self._rotate_command)

+ 9 - 9
nicegui/elements/scene_objects.py

@@ -1,5 +1,5 @@
 from __future__ import annotations
-from typing import Optional
+from typing import List, Optional
 from .scene_object3d import Object3D
 
 class Scene(Object3D):
@@ -47,7 +47,7 @@ class Cylinder(Object3D):
 class Extrusion(Object3D):
 
     def __init__(self,
-                 outline: list[list[float, float]],
+                 outline: List[List[float, float]],
                  height: float,
                  wireframe: bool = False,
                  ):
@@ -64,18 +64,18 @@ class Stl(Object3D):
 class Line(Object3D):
 
     def __init__(self,
-                 start: list[float, float, float],
-                 end: list[float, float, float],
+                 start: List[float, float, float],
+                 end: List[float, float, float],
                  ):
         super().__init__('line', start, end)
 
 class Curve(Object3D):
 
     def __init__(self,
-                 start: list[float, float, float],
-                 control1: list[float, float, float],
-                 control2: list[float, float, float],
-                 end: list[float, float, float],
+                 start: List[float, float, float],
+                 control1: List[float, float, float],
+                 control2: List[float, float, float],
+                 end: List[float, float, float],
                  num_points: int = 20,
                  ):
         super().__init__('curve', start, control1, control2, end, num_points)
@@ -84,6 +84,6 @@ class Texture(Object3D):
 
     def __init__(self,
                  url: str,
-                 coordinates: list[list[Optional[list[float]]]],
+                 coordinates: List[List[Optional[List[float]]]],
                  ):
         super().__init__('texture', url, coordinates)

+ 2 - 2
nicegui/elements/select.py

@@ -1,11 +1,11 @@
 import justpy as jp
-from typing import Awaitable, Callable, Optional, Union
+from typing import Awaitable, Callable, Dict, List, Optional, Union
 from .choice_element import ChoiceElement
 
 class Select(ChoiceElement):
 
     def __init__(self,
-                 options: Union[list, dict],
+                 options: Union[List, Dict],
                  *,
                  value: any = None,
                  on_change: Optional[Union[Callable, Awaitable]] = None,

+ 2 - 2
nicegui/elements/toggle.py

@@ -1,11 +1,11 @@
 import justpy as jp
-from typing import Awaitable, Callable, Optional, Union
+from typing import Awaitable, Callable, Dict, List, Optional, Union
 from .choice_element import ChoiceElement
 
 class Toggle(ChoiceElement):
 
     def __init__(self,
-                 options: Union[list, dict],
+                 options: Union[List, Dict],
                  *,
                  value: any = None,
                  on_change: Optional[Union[Callable, Awaitable]] = None,

+ 4 - 4
nicegui/globals.py

@@ -1,7 +1,7 @@
 from __future__ import annotations
 import asyncio
 import logging
-from typing import TYPE_CHECKING
+from typing import List, TYPE_CHECKING
 if TYPE_CHECKING:
     from starlette.applications import Starlette
     import justpy as jp
@@ -10,7 +10,7 @@ if TYPE_CHECKING:
 
 app: 'Starlette'
 config: 'Config'
-page_stack: list['Page'] = []
-view_stack: list['jp.HTMLBaseComponent'] = []
-tasks: list[asyncio.tasks.Task] = []
+page_stack: List['Page'] = []
+view_stack: List['jp.HTMLBaseComponent'] = []
+tasks: List[asyncio.tasks.Task] = []
 log: logging.Logger = logging.getLogger('nicegui')