Duplicate Check
Describe the bug
The uses of dataclass_transform decorator in flet (at
and
) do not list any
field_specifiers. According to the Python typing spec, this means that there are
no field-specifier functions respected, including
dataclasses.field.
At runtime, both of these dataclass-transform functions are wrappers around dataclasses.dataclass, so they do in fact respect dataclasses.field. And many of the classes using these transforms do specify field metadata via dataclasses.field calls.
Python type checkers (at least mypy, pyright, pyrefly, and ty) are not respecting these dataclasses.field() calls as intended. In many cases, these calls are used to specify init=False, which is not being respected -- but this passes silently, because the field is considered as having a default value, which makes it an optional parameter in __init__.
The dataclass_transform calls should be updated to look like @dataclass_transform(field_specifiers=(Field, field)). This would help type checkers better understand the actual semantics of the flet classes using these transforms.
Code sample
The following code fails at runtime (DataTable2 does not actually accept an argument data_row_min_height), but type checkers accept it. The reason is because field(init=False) is not being respected by type checkers at
|
data_row_min_height: None = field( |
, because of the lacking
field_specifiers in the
dataclass_transform decorator at
Code
from flet_datatable2 import DataTable2
DataTable2(columns=[], data_row_min_height=None)
To reproduce
The given repro code fails at runtime, but type checkers fail to catch the error, due to incorrect use of dataclass_transform in flet (using dataclasses.field as a field specifier, without listing field_specifiers).
Expected behavior
Type checkers should correctly tell the user that data_row_min_height is not a valid constructor argument to DataTable2.
Screenshots / Videos
Captures
[Upload media here]
Operating System
macOS
Operating system details
Sequoia
Flet version
0.84.0
Regression
No, it isn't
Suggestions
Add field_specifiers=(dataclasses.field, dataclasses.Field) to your dataclass_transform calls.
Logs
Logs
Additional details
No response
Duplicate Check
Describe the bug
The uses of
dataclass_transformdecorator in flet (atflet/sdk/python/packages/flet/src/flet/controls/base_control.py
Line 89 in a829bd1
flet/sdk/python/packages/flet/src/flet/controls/base_control.py
Line 89 in a829bd1
field_specifiers. According to the Python typing spec, this means that there are no field-specifier functions respected, includingdataclasses.field.At runtime, both of these dataclass-transform functions are wrappers around
dataclasses.dataclass, so they do in fact respectdataclasses.field. And many of the classes using these transforms do specify field metadata viadataclasses.fieldcalls.Python type checkers (at least mypy, pyright, pyrefly, and ty) are not respecting these
dataclasses.field()calls as intended. In many cases, these calls are used to specifyinit=False, which is not being respected -- but this passes silently, because the field is considered as having a default value, which makes it an optional parameter in__init__.The
dataclass_transformcalls should be updated to look like@dataclass_transform(field_specifiers=(Field, field)). This would help type checkers better understand the actual semantics of the flet classes using these transforms.Code sample
The following code fails at runtime (
DataTable2does not actually accept an argumentdata_row_min_height), but type checkers accept it. The reason is becausefield(init=False)is not being respected by type checkers atflet/sdk/python/packages/flet-datatable2/src/flet_datatable2/datatable2.py
Line 136 in a829bd1
field_specifiersin thedataclass_transformdecorator atflet/sdk/python/packages/flet/src/flet/controls/base_control.py
Line 89 in a829bd1
Code
To reproduce
The given repro code fails at runtime, but type checkers fail to catch the error, due to incorrect use of
dataclass_transformin flet (usingdataclasses.fieldas a field specifier, without listingfield_specifiers).Expected behavior
Type checkers should correctly tell the user that
data_row_min_heightis not a valid constructor argument toDataTable2.Screenshots / Videos
Captures
[Upload media here]
Operating System
macOS
Operating system details
Sequoia
Flet version
0.84.0
Regression
No, it isn't
Suggestions
Add
field_specifiers=(dataclasses.field, dataclasses.Field)to yourdataclass_transformcalls.Logs
Logs
[Paste your logs here]Additional details
No response