Skip to content

Commit 1dcac85

Browse files
authored
Merge pull request #25 from T-Dynamos/update
add backward compatibility class attrs
2 parents 8ed1f82 + e6a4444 commit 1dcac85

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
from __future__ import annotations
22

3-
from typing import List, Optional
3+
from typing import List
44

55
from materialyoucolor.dynamiccolor.color_spec import (
66
COLOR_NAMES,
77
ColorSpecDelegate,
88
get_spec,
99
)
1010
from materialyoucolor.dynamiccolor.dynamic_color import DynamicColor
11-
from materialyoucolor.dynamiccolor.dynamic_scheme import DynamicScheme
1211

1312

1413
class MaterialDynamicColors:
1514
content_accent_tone_delta = 15.0
1615

1716
def __init__(self, spec="2025"):
1817
self.color_spec: ColorSpecDelegate = get_spec(spec)
19-
20-
# define them dynamically
21-
for color_name in COLOR_NAMES:
22-
exec(
23-
f"@property\ndef {color_name}(self) -> DynamicColor:\n\treturn self.color_spec.{color_name}()"
24-
)
18+
for name in COLOR_NAMES:
19+
setattr(self, name, getattr(self.color_spec, name)())
2520

2621
@property
2722
def all_colors(self) -> List[DynamicColor]:
2823
colors = [getattr(self, _) for _ in COLOR_NAMES]
2924
return [c for c in colors if c is not None]
25+
26+
27+
# backward compatibility class attrs
28+
_spec = get_spec("2025")
29+
for name in COLOR_NAMES:
30+
setattr(MaterialDynamicColors, name, getattr(_spec, name)())

0 commit comments

Comments
 (0)