Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

bug: dataclass_transform() uses should include `field_specifiers` argument

Aperta Adatta ai principianti
#6,377 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python

Direzione di ricerca

Inizia in sdk/python/packages/flet/src/flet/controls/base_control.py, intorno alle chiamate a dataclass_transform, quindi esamina sdk/python/packages/flet-datatable2/src/flet_datatable2/datatable2.py, intorno all’uso di field(init=False). Usa la riproduzione di DataTable2 con un type checker; il lavoro è terminato quando il transform elenca gli specificatori dei campi di dataclass e i type checker rifiutano data_row_min_height come argomento del costruttore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Duplicate Check
Describe the bug

The uses of dataclass_transform decorator in flet (at https://github.com/flet-dev/flet/blob/a829bd1a97f8b0ebb5969af7a44952cfca08cdb3/sdk/python/packages/flet/src/flet/controls/base_control.py#L89 and https://github.com/flet-dev/flet/blob/a829bd1a97f8b0ebb5969af7a44952cfca08cdb3/sdk/python/packages/flet/src/flet/controls/base_control.py#L89 ) 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 https://github.com/flet-dev/flet/blob/a829bd1a97f8b0ebb5969af7a44952cfca08cdb3/sdk/python/packages/flet-datatable2/src/flet_datatable2/datatable2.py#L136, because of the lacking field_specifiers in the dataclass_transform decorator at https://github.com/flet-dev/flet/blob/a829bd1a97f8b0ebb5969af7a44952cfca08cdb3/sdk/python/packages/flet/src/flet/controls/base_control.py#L89

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

Lingua principale
Python
Stelle
17.4k
Fork
737
Merge medio
1g 7h
PR unite (30g)
51

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di flet-dev/flet

Tutte le issue di flet-dev/flet

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.