bug: dataclass_transform() uses should include `field_specifiers` argument
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
- Ambito
- developer-experience
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
Duplicate Check
- I have searched the opened issues and there are no duplicates
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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di flet-dev/flet
-
feature: python 3.15 supportApertafeature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
flet-dev/flet#6985 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
flet build: common [tool.flet.deep_linking] is ignored on Android and iOSForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug packaging platform: mobile
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug: [packaging] editing requirements.txt does not trigger pip reinstall (stale hash), produces APK with missing/empty site-packagesForse già presa @ndonkoHenri l’ha presa 2 giorni fa. Apertabug
flet-dev/flet#6994 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug: `flet test` on freshly created project fails on Windows with an empty windowForse già presa @ndonkoHenri l’ha presa 2 giorni fa. Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
flet-dev/flet#6993 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di flet-dev/flet
Issue simili
-
The changelog workflow excludes otelbot but not dependabot, so every Dependabot pull request fails the changelog checkForse già presa @ocelotl l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
open-telemetry/opentelemetry-python#5825 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
cuga-project/cuga-agent#1020 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
microsoft/playwright#43640 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
stac-utils/stac-fastapi-elasticsearch-opensearch#965 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno