Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug fixes

* Fix mypy inferring `type[Never]` for classes decorated with `@control("Name")`: the overload that takes arguments now accepts only a string `dart_widget_name` ([#7085](https://github.com/flet-dev/flet/issues/7085), [#7087](https://github.com/flet-dev/flet/pull/7087)) by @joaoaracheski.
* Fix type checkers ignoring `dataclasses.field()` arguments such as `init=False` on `@control` and `@value` classes, by declaring `dataclasses.field` as a field specifier ([#6377](https://github.com/flet-dev/flet/issues/6377), [#7084](https://github.com/flet-dev/flet/pull/7084)) by @joaoaracheski.

## 1.1.2

Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet/src/flet/controls/base_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def control(
...


@dataclass_transform()
@dataclass_transform(field_specifiers=(field,))
def control(
dart_widget_name: Optional[Union[type[T], str]] = None,
*,
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet/src/flet/controls/value_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class explicitly. It is exposed so that `isinstance(obj, Value)`
"""


@dataclass_transform()
@dataclass_transform(field_specifiers=(dataclasses.field,))
def value(
cls: Optional[type] = None,
**dataclass_kwargs: Any,
Expand Down
12 changes: 12 additions & 0 deletions sdk/python/packages/flet/tests/test_base_control.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import dataclasses
import sys
import typing

import pytest

import flet as ft
from flet.controls.base_control import control
from flet.controls.value_types import value


def test_controls_equality():
Expand Down Expand Up @@ -47,3 +49,13 @@ def test_control_args_overload_accepts_only_str_name():
_, with_args = typing.get_overloads(control)
hints = typing.get_type_hints(with_args)
assert hints["dart_widget_name"] == typing.Optional[str]


def test_dataclass_transforms_declare_field_specifiers():
"""
Type checkers only honor `dataclasses.field()` arguments (e.g. `init=False`)
on `@control` and `@value` classes when `field` is a declared field specifier.
"""
for decorator in (control, value):
transform = decorator.__dataclass_transform__
assert dataclasses.field in transform["field_specifiers"]
Loading