Skip to content

Commit

Permalink
Text.style type Deprecation warning (#2286)
Browse files Browse the repository at this point in the history
* initial commit

* remove DeprecationWarning
  • Loading branch information
ndonkoHenri authored Jan 8, 2024
1 parent 43676d1 commit 9de53ea
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dataclasses
from enum import Enum
from typing import Any, List, Optional, Union
from warnings import warn

from flet_core.constrained_control import ConstrainedControl
from flet_core.control import OptionalNumber
Expand Down Expand Up @@ -120,7 +121,7 @@ def __init__(
size: OptionalNumber = None,
weight: Optional[FontWeight] = None,
italic: Optional[bool] = None,
style: Optional[Union[TextThemeStyle, TextStyle]] = None,
style: Union[TextThemeStyle, TextStyle, None] = None,
theme_style: Optional[TextThemeStyle] = None,
max_lines: Optional[int] = None,
overflow: TextOverflow = TextOverflow.NONE,
Expand Down Expand Up @@ -260,16 +261,21 @@ def __set_weight(self, value: FontWeightString):

# style
@property
def style(self) -> Optional[Union[TextThemeStyle, TextStyle]]:
def style(self) -> Union[TextThemeStyle, TextStyle, None]:
return self.__style

@style.setter
def style(self, value: Optional[Union[TextThemeStyle, TextStyle]]):
def style(self, value: Union[TextThemeStyle, TextStyle, None]):
self.__style = value
if isinstance(value, (TextThemeStyle, str)) or value is None:
self._set_attr(
"style", value.value if isinstance(value, TextThemeStyle) else value
)
warn(
"If you wish to set the TextThemeStyle, use `Text.theme_style` instead. "
"The `Text.style` property should be used to set the TextStyle only.",
stacklevel=2,
)

# theme_style
@property
Expand All @@ -278,7 +284,7 @@ def theme_style(self):

@theme_style.setter
def theme_style(self, value: Optional[TextThemeStyle]):
self._set_attr("theme_style", value.value if value is not None else None)
self._set_attr("theme_style", value.value if isinstance(value, TextThemeStyle) else value)

# italic
@property
Expand Down

0 comments on commit 9de53ea

Please sign in to comment.