Skip to content

Commit f80e8ff

Browse files
committed
fix: update DataColumn control to use kw_only=True for tooltip property only
1 parent c4d5765 commit f80e8ff

File tree

1 file changed

+47
-25
lines changed
  • sdk/python/packages/flet/src/flet/controls/material

1 file changed

+47
-25
lines changed

sdk/python/packages/flet/src/flet/controls/material/datatable.py

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ class DataColumnSortEvent(Event["DataColumn"]):
3030
ascending: bool = field(metadata={"data_field": "asc"})
3131

3232

33-
@control("DataColumn", kw_only=True)
33+
@control("DataColumn")
3434
class DataColumn(Control):
3535
"""
3636
Column configuration for a [`DataTable`][flet.DataTable].
3737
3838
Raises:
39-
AssertionError: if the [`label`][(c).] is neither a string nor a visible control
39+
AssertionError: If the [`label`][(c).] is neither a string nor
40+
a visible control.
4041
"""
4142

4243
label: StrOrControl
@@ -55,7 +56,7 @@ class DataColumn(Control):
5556
The contents of cells of columns containing numeric data are right-aligned.
5657
"""
5758

58-
tooltip: Optional[str] = None
59+
tooltip: Optional[str] = field(default=None, kw_only=True)
5960
"""
6061
The column heading's tooltip.
6162
@@ -92,7 +93,8 @@ class DataCell(Control):
9293
The data for a cell of a [`DataTable`][flet.DataTable].
9394
9495
Raises:
95-
AssertionError: If the [`content`][(c).] is neither a string nor a visible control.
96+
AssertionError: If the [`content`][(c).] is neither a string nor a visible
97+
control.
9698
"""
9799

98100
content: StrOrControl
@@ -102,11 +104,12 @@ class DataCell(Control):
102104
Typically a [`Text`][flet.Text] control or a [`Dropdown`][flet.Dropdown] control.
103105
104106
If the cell has no data, then a `Text` widget with placeholder text should be
105-
provided instead, and [`placeholder`][flet.DataCell.placeholder] should be set to `True`.
107+
provided instead, and [`placeholder`][flet.DataCell.placeholder] should be set to
108+
`True`.
106109
107110
To lay out multiple children, let this
108-
control's child be a container-like control such as [`Row`][flet.Row], [`Column`][flet.Column],
109-
or [`Stack`][flet.Stack], which have `controls` property.
111+
control's child be a container-like control such as [`Row`][flet.Row],
112+
[`Column`][flet.Column], or [`Stack`][flet.Stack], which have `controls` property.
110113
"""
111114

112115
placeholder: bool = False
@@ -247,7 +250,8 @@ class DataRow(Control):
247250
"""
248251
Called if the row is long-pressed.
249252
250-
If a [`DataCell`][flet.DataCell] in the row has its [`DataCell.on_tap`][flet.DataCell.on_tap],
253+
If a [`DataCell`][flet.DataCell] in the row has its
254+
[`DataCell.on_tap`][flet.DataCell.on_tap],
251255
[`DataCell.on_double_tap`][flet.DataCell.on_double_tap],
252256
[`DataCell.on_long_press`][flet.DataCell.on_long_press],
253257
[`DataCell.on_tap_cancel`][flet.DataCell.on_tap_cancel]
@@ -260,8 +264,8 @@ class DataRow(Control):
260264
"""
261265
Called when the user selects or unselects a selectable row.
262266
263-
If this is not null, then this row is selectable. The current selection state of this
264-
row is given by selected.
267+
If this is not null, then this row is selectable. The current selection state of
268+
this row is given by selected.
265269
266270
If any row is selectable, then the table's heading row will have a checkbox that
267271
can be checked to select all selectable rows (and which is checked if all the rows
@@ -272,7 +276,8 @@ class DataRow(Control):
272276
273277
If a [`DataCell`][flet.DataCell] in the row has its
274278
[`DataCell.on_tap`][flet.DataCell.on_tap] callback defined, that
275-
callback behavior overrides the gesture behavior of the row for that particular cell.
279+
callback behavior overrides the gesture behavior of the row for that particular
280+
cell.
276281
"""
277282

278283
def __contains__(self, item):
@@ -292,8 +297,10 @@ class DataTable(ConstrainedControl):
292297
293298
Raises:
294299
AssertionError: If there are no visible [`columns`][(c).].
295-
AssertionError: If any visible row does not contain exactly as many visible [`cells`][flet.DataRow.cells] as there are visible [`columns`][(c).].
296-
AssertionError: If [`data_row_min_height`][(c).] is greater than [`data_row_max_height`][(c).].
300+
AssertionError: If any visible row does not contain exactly as many visible
301+
[`cells`][flet.DataRow.cells] as there are visible [`columns`][(c).].
302+
AssertionError: If [`data_row_min_height`][(c).] is greater than
303+
[`data_row_max_height`][(c).].
297304
AssertionError: If [`divider_thickness`][(c).] is negative.
298305
AssertionError: If [`sort_column_index`][(c).] is out of range.
299306
"""
@@ -311,7 +318,8 @@ class DataTable(ConstrainedControl):
311318

312319
sort_ascending: bool = False
313320
"""
314-
Whether the column mentioned in [`sort_column_index`][flet.DataTable.sort_column_index],
321+
Whether the column mentioned in
322+
[`sort_column_index`][flet.DataTable.sort_column_index],
315323
if any, is sorted in ascending order.
316324
317325
If `True`, the order is ascending (meaning the rows with the smallest values for
@@ -390,7 +398,8 @@ class DataTable(ConstrainedControl):
390398
"""
391399
The background color for the data rows.
392400
393-
The effective background color can be made to depend on the [`ControlState`][flet.ControlState]
401+
The effective background color can be made to depend on the
402+
[`ControlState`][flet.ControlState]
394403
state, i.e. if the row is selected, pressed, hovered, focused, disabled or enabled.
395404
The color is painted as an overlay to the row. To make sure that the row's InkWell
396405
is visible (when pressed, hovered and focused), it is recommended to use a
@@ -401,7 +410,11 @@ class DataTable(ConstrainedControl):
401410
"""
402411
The minimum height of each row (excluding the row that contains column headings).
403412
404-
Defaults to `48.0` and must be less than or equal to [`data_row_max_height`][flet.DataTable.data_row_max_height].
413+
Defaults to `48.0`.
414+
415+
Note:
416+
Must be less than or equal to
417+
[`data_row_max_height`][flet.DataTable.data_row_max_height].
405418
"""
406419

407420
data_row_max_height: Optional[Number] = None
@@ -410,7 +423,11 @@ class DataTable(ConstrainedControl):
410423
Set to `float("inf")` for the height of each row to adjust automatically with its
411424
content.
412425
413-
Defaults to `48.0` and must be greater than or equal to `data_row_min_height`.
426+
Defaults to `48.0`.
427+
428+
Note:
429+
Must be greater than or equal to
430+
[`data_row_min_height`][flet.DataTable.data_row_min_height].
414431
"""
415432

416433
data_text_style: Optional[TextStyle] = None
@@ -440,10 +457,11 @@ class DataTable(ConstrainedControl):
440457
"""
441458
The background color for the heading row.
442459
443-
The effective background color can be made to depend on the [`ControlState`][flet.ControlState]
444-
state, i.e. if the row is pressed, hovered, focused when sorted. The color is
445-
painted as an overlay to the row. To make sure that the row's InkWell is visible
446-
(when pressed, hovered and focused), it is recommended to use a translucent color.
460+
The effective background color can be made to depend on the
461+
[`ControlState`][flet.ControlState] state, i.e. if the row is pressed, hovered,
462+
focused when sorted. The color is painted as an overlay to the row. To make sure
463+
that the row's InkWell is visible (when pressed, hovered and focused), it is
464+
recommended to use a translucent color.
447465
"""
448466

449467
heading_row_height: Optional[Number] = None
@@ -475,7 +493,8 @@ class DataTable(ConstrainedControl):
475493
Invoked when the user selects or unselects every row, using the checkbox in the
476494
heading row.
477495
478-
If this is `None`, then the [`DataRow.on_select_change`][flet.DataRow.on_select_change]
496+
If this is `None`, then the
497+
[`DataRow.on_select_change`][flet.DataRow.on_select_change]
479498
callback of every row in the table is invoked appropriately instead.
480499
481500
To control whether a particular row is selectable or not, see
@@ -509,14 +528,17 @@ def before_update(self):
509528
or self.data_row_max_height is None
510529
or (self.data_row_min_height <= self.data_row_max_height)
511530
), (
512-
f"data_row_min_height ({self.data_row_min_height}) must be less than or equal to data_row_max_height ({self.data_row_max_height})"
531+
f"data_row_min_height ({self.data_row_min_height}) must be less than or "
532+
f"equal to data_row_max_height ({self.data_row_max_height})"
513533
)
514534
assert self.divider_thickness is None or self.divider_thickness >= 0, (
515-
f"divider_thickness must be greater than or equal to 0, got {self.divider_thickness}"
535+
f"divider_thickness must be greater than or equal to 0, "
536+
f"got {self.divider_thickness}"
516537
)
517538
assert self.sort_column_index is None or (
518539
0 <= self.sort_column_index < visible_columns_count
519540
), (
520-
f"sort_column_index ({self.sort_column_index}) must be greater than or equal to 0 and less than the "
541+
f"sort_column_index ({self.sort_column_index}) must be greater than or "
542+
f"equal to 0 and less than the "
521543
f"number of visible columns ({visible_columns_count})"
522544
)

0 commit comments

Comments
 (0)