Skip to content

Commit 4fb3cc1

Browse files
Rollback to original colors.with_opacity() implementation (#4340)
Close #4336
1 parent 0f7b14b commit 4fb3cc1

File tree

1 file changed

+17
-17
lines changed
  • sdk/python/packages/flet/src/flet/core

1 file changed

+17
-17
lines changed

sdk/python/packages/flet/src/flet/core/colors.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737

3838
import random
3939
from enum import Enum, EnumMeta
40-
from typing import Dict, List, Optional, Union
40+
from typing import TYPE_CHECKING, Dict, List, Optional, Union
4141
from warnings import warn
4242

43+
if TYPE_CHECKING:
44+
from flet.core.types import ColorValue
45+
4346
from flet.utils import deprecated
4447

4548

@@ -56,9 +59,16 @@ def __getattribute__(self, item):
5659

5760

5861
class colors(str, Enum, metaclass=ColorsDeprecated):
59-
def with_opacity(self, opacity: Union[int, float]) -> str:
62+
@staticmethod
63+
@deprecated(
64+
reason="Use Colors.with_opacity() method instead.",
65+
version="0.25.0",
66+
delete_version="0.28.0",
67+
)
68+
def with_opacity(opacity: Union[int, float], color: "ColorValue") -> str:
6069
assert 0 <= opacity <= 1, "opacity must be between 0 and 1"
61-
return f"{self.value},{opacity}"
70+
color_str = color.value if isinstance(color, Enum) else color
71+
return f"{color_str},{opacity}"
6272

6373
@staticmethod
6474
def random():
@@ -416,21 +426,11 @@ def random_color():
416426

417427

418428
class Colors(str, Enum):
419-
def with_opacity(self, opacity: Union[int, float]) -> str:
420-
"""
421-
Returns the color with the specified opacity.
422-
423-
Args:
424-
opacity: The opacity value, which must be between 0 and 1.
425-
426-
Returns:
427-
A string representing the color value with the specified opacity appended.
428-
429-
Raises:
430-
AssertionError: If the opacity is not between 0 and 1 (inclusive).
431-
"""
429+
@staticmethod
430+
def with_opacity(opacity: Union[int, float], color: "ColorValue") -> str:
432431
assert 0 <= opacity <= 1, "opacity must be between 0 and 1"
433-
return f"{self.value},{opacity}"
432+
color_str = color.value if isinstance(color, Enum) else color
433+
return f"{color_str},{opacity}"
434434

435435
@staticmethod
436436
def random(

0 commit comments

Comments
 (0)