Skip to content

Commit

Permalink
[Typing] Using Sequence instead of list (#3661)
Browse files Browse the repository at this point in the history
* add

* Review: cast to list in the setter | return type = list

* Review: cast to list in the setter | return type = list

* fix

* fix

* update

* update

---------

Co-authored-by: ndonkoHenri <[email protected]>
  • Loading branch information
zrr1999 and ndonkoHenri authored Jul 25, 2024
1 parent 378e3f3 commit 27ffc23
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 68 deletions.
8 changes: 4 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/column.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union, Callable
from typing import Any, List, Optional, Sequence, Union, Callable

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -58,7 +58,7 @@ def main(page: ft.Page):

def __init__(
self,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
alignment: Optional[MainAxisAlignment] = None,
horizontal_alignment: Optional[CrossAxisAlignment] = None,
spacing: OptionalNumber = None,
Expand Down Expand Up @@ -236,5 +236,5 @@ def controls(self):
return self.__controls

@controls.setter
def controls(self, value: Optional[List[Control]]):
self.__controls = value if value is not None else []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value is not None else []
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union
from typing import Any, List, Optional, Sequence, Union

from flet_core.constrained_control import ConstrainedControl
from flet_core.control import Control, OptionalNumber
Expand All @@ -24,7 +24,7 @@ class CupertinoPicker(ConstrainedControl):

def __init__(
self,
controls: List[Control],
controls: Sequence[Control],
item_extent: OptionalNumber = None,
selected_index: Optional[int] = None,
bgcolor: Optional[str] = None,
Expand Down Expand Up @@ -209,8 +209,8 @@ def controls(self) -> List[Control]:
return self.__controls

@controls.setter
def controls(self, value: Optional[List[Control]]):
self.__controls = value if value is not None else []
def controls(self, value: Sequence[Control]):
self.__controls = list(value)

# on_change
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Union, List
from typing import Any, Optional, Sequence, Union, List

from flet_core.constrained_control import ConstrainedControl
from flet_core.control import OptionalNumber, Control
Expand All @@ -25,7 +25,7 @@ class CupertinoSegmentedButton(ConstrainedControl):

def __init__(
self,
controls: List[Control],
controls: Sequence[Control],
selected_index: Optional[int] = None,
selected_color: Optional[str] = None,
unselected_color: Optional[str] = None,
Expand Down Expand Up @@ -125,8 +125,8 @@ def controls(self) -> List[Control]:
return self.__controls

@controls.setter
def controls(self, value: List[Control]):
self.__controls = value
def controls(self, value: Sequence[Control]):
self.__controls = list(value)

# border_color
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Union, List
from typing import Any, Optional, Sequence, Union, List

from flet_core.constrained_control import ConstrainedControl
from flet_core.control import OptionalNumber, Control
Expand All @@ -24,7 +24,7 @@ class CupertinoSlidingSegmentedButton(ConstrainedControl):

def __init__(
self,
controls: List[Control],
controls: Sequence[Control],
selected_index: Optional[int] = None,
bgcolor: Optional[str] = None,
thumb_color: Optional[str] = None,
Expand Down Expand Up @@ -117,8 +117,8 @@ def controls(self):
return self.__controls

@controls.setter
def controls(self, value: List[Control]):
self.__controls = value
def controls(self, value: Sequence[Control]):
self.__controls = list(value)

# selected_index
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union
from typing import Any, Optional, Sequence, Union

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -176,7 +176,7 @@ class ExpansionPanelList(ConstrainedControl):

def __init__(
self,
controls: Optional[List[ExpansionPanel]] = None,
controls: Optional[Sequence[ExpansionPanel]] = None,
divider_color: Optional[str] = None,
elevation: OptionalNumber = None,
expanded_header_padding: PaddingValue = None,
Expand Down Expand Up @@ -317,8 +317,8 @@ def controls(self):
return self.__controls

@controls.setter
def controls(self, value: Optional[List[ExpansionPanel]]):
self.__controls = value if value is not None else []
def controls(self, value: Optional[Sequence[ExpansionPanel]]):
self.__controls = list(value) if value is not None else []

# on_change
@property
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/expansion_tile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Any, List, Optional, Union
from typing import Any, List, Optional, Union, Sequence

from flet_core.adaptive_control import AdaptiveControl
from flet_core.alignment import Alignment
Expand Down Expand Up @@ -40,7 +40,7 @@ class ExpansionTile(ConstrainedControl, AdaptiveControl):
def __init__(
self,
title: Control,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
subtitle: Optional[Control] = None,
leading: Optional[Control] = None,
trailing: Optional[Control] = None,
Expand Down Expand Up @@ -193,8 +193,8 @@ def controls(self):
return self.__controls

@controls.setter
def controls(self, value: Optional[List[Control]]):
self.__controls = value if value is not None else []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value is not None else []

# controls_padding
@property
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/grid_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union, Callable
from typing import Any, List, Optional, Union, Callable, Sequence

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -67,7 +67,7 @@ def main(page: ft.Page):

def __init__(
self,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
horizontal: Optional[bool] = None,
runs_count: Optional[int] = None,
max_extent: Optional[int] = None,
Expand Down Expand Up @@ -272,8 +272,8 @@ def controls(self):
return self.__controls

@controls.setter
def controls(self, value):
self.__controls = value if value is not None else []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value is not None else []

# clip_behavior
@property
Expand Down
10 changes: 5 additions & 5 deletions sdk/python/packages/flet-core/src/flet_core/list_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union, Callable
from typing import Any, List, Optional, Union, Callable, Sequence

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -59,7 +59,7 @@ def main(page: ft.Page):

def __init__(
self,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
horizontal: Optional[bool] = None,
spacing: OptionalNumber = None,
item_extent: OptionalNumber = None,
Expand Down Expand Up @@ -249,12 +249,12 @@ def padding(self, value: PaddingValue):

# controls
@property
def controls(self):
def controls(self) -> List[Control]:
return self.__controls

@controls.setter
def controls(self, value):
self.__controls = value if value is not None else []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value is not None else []

# clip_behavior
@property
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/menu_bar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Sequence, Union

from flet_core.alignment import Alignment
from flet_core.border import BorderSide
Expand Down Expand Up @@ -57,7 +57,7 @@ class MenuBar(Control):

def __init__(
self,
controls: List[Control],
controls: Sequence[Control],
clip_behavior: Optional[ClipBehavior] = None,
style: Optional[MenuStyle] = None,
#
Expand Down Expand Up @@ -116,8 +116,8 @@ def controls(self) -> List[Control]:
return self.__controls

@controls.setter
def controls(self, value: List[Control]):
self.__controls = value
def controls(self, value: Sequence[Control]):
self.__controls = list(value)

# clip_behavior
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Any, List, Optional
from typing import Any, List, Optional, Sequence

from flet_core.buttons import OutlinedBorder
from flet_core.control import Control
Expand Down Expand Up @@ -169,7 +169,7 @@ def handle_change(e):

def __init__(
self,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
open: bool = False,
selected_index: Optional[int] = None,
bgcolor: Optional[str] = None,
Expand Down Expand Up @@ -238,8 +238,8 @@ def controls(self) -> Optional[List[Control]]:
return self.__controls

@controls.setter
def controls(self, value: Optional[List[Control]]):
self.__controls = value or []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value is not None else []

# selected_index
@property
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Dict,
List,
Optional,
Sequence,
Tuple,
Type,
TypeVar,
Expand Down Expand Up @@ -1853,8 +1854,8 @@ def controls(self) -> Optional[List[Control]]:
return self.__default_view.controls

@controls.setter
def controls(self, value: Optional[List[Control]]):
self.__default_view.controls = value if value is not None else []
def controls(self, value: Optional[Sequence[Control]]):
self.__default_view.controls = list(value) if value is not None else []

# appbar
@property
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/responsive_row.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union
from typing import Any, List, Optional, Union, Sequence

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -51,7 +51,7 @@ def main(page: ft.Page):

def __init__(
self,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
columns: Optional[ResponsiveNumber] = None,
alignment: Optional[MainAxisAlignment] = None,
vertical_alignment: Optional[CrossAxisAlignment] = None,
Expand Down Expand Up @@ -209,5 +209,5 @@ def controls(self):
return self.__controls

@controls.setter
def controls(self, value):
self.__controls = value if value is not None else []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value is not None else []
8 changes: 4 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/row.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union, Callable
from typing import Any, List, Optional, Union, Callable, Sequence

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -61,7 +61,7 @@ def main(page: ft.Page):

def __init__(
self,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
alignment: Optional[MainAxisAlignment] = None,
vertical_alignment: Optional[CrossAxisAlignment] = None,
spacing: OptionalNumber = None,
Expand Down Expand Up @@ -240,5 +240,5 @@ def controls(self) -> List[Control]:
return self.__controls

@controls.setter
def controls(self, value: Optional[List[Control]]):
self.__controls = value if value else []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value else []
8 changes: 4 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/search_bar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Union, Sequence

from flet_core.border import BorderSide
from flet_core.buttons import OutlinedBorder
Expand Down Expand Up @@ -32,7 +32,7 @@ class SearchBar(ConstrainedControl):

def __init__(
self,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
value: Optional[str] = None,
bar_leading: Optional[Control] = None,
bar_trailing: Optional[List[Control]] = None,
Expand Down Expand Up @@ -395,8 +395,8 @@ def controls(self):
return self.__controls

@controls.setter
def controls(self, value: Optional[List[Control]]):
self.__controls = value if value is not None else []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value is not None else []

# value
@property
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/stack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Any, List, Optional, Union
from typing import Any, List, Optional, Union, Sequence

from flet_core.adaptive_control import AdaptiveControl
from flet_core.alignment import Alignment
Expand Down Expand Up @@ -74,7 +74,7 @@ def main(page: ft.Page):

def __init__(
self,
controls: Optional[List[Control]] = None,
controls: Optional[Sequence[Control]] = None,
clip_behavior: Optional[ClipBehavior] = None,
alignment: Optional[Alignment] = None,
fit: Optional[StackFit] = None,
Expand Down Expand Up @@ -163,8 +163,8 @@ def controls(self):
return self.__controls

@controls.setter
def controls(self, value):
self.__controls = value if value is not None else []
def controls(self, value: Optional[Sequence[Control]]):
self.__controls = list(value) if value is not None else []

# clip_behavior
@property
Expand Down
Loading

0 comments on commit 27ffc23

Please sign in to comment.