Skip to content

bug: dataclass_transform() uses should include field_specifiers argument #6377

@carljm

Description

@carljm

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

, 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
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions