Skip to content

Commit f828f5e

Browse files
committed
Change flake8 max-complexity from 7 to 6
1 parent d553cfc commit f828f5e

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ build-backend = "poetry.core.masonry.api"
8282

8383
[tool.flake8]
8484
max-line-length = 104
85-
max-complexity = 7
85+
max-complexity = 6
8686
docstring-convention = "google"
8787
per-file-ignores = ["**/__init__.py:F401", "examples/**:D103"]
8888

qdarktheme/_filter.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ def _svg_resources() -> dict[str, str]:
3737
return json.loads(_resources.SVG_RESOURCES)
3838

3939

40+
def _transform(color: Color, color_state: dict[str, float]) -> Color:
41+
if color_state.get("transparent"):
42+
color = color.transparent(color_state["transparent"])
43+
if color_state.get("darken"):
44+
color = color.darken(color_state["darken"])
45+
if color_state.get("lighten"):
46+
return color.lighten(color_state["lighten"])
47+
return color
48+
49+
4050
def color(color_info: str | dict[str, str | dict], state: str | None = None) -> Color:
4151
"""Filter for template engine. This filter convert color info data to color object."""
4252
if isinstance(color_info, str):
@@ -48,17 +58,8 @@ def color(color_info: str | dict[str, str | dict], state: str | None = None) ->
4858
if state is None:
4959
return color
5060

51-
color_state = color_info[state]
52-
if isinstance(color_state, str):
53-
return Color.from_hex(color_state)
54-
55-
if color_state.get("transparent"):
56-
color = color.transparent(color_state["transparent"])
57-
if color_state.get("darken"):
58-
color = color.darken(color_state["darken"])
59-
if color_state.get("lighten"):
60-
return color.lighten(color_state["lighten"])
61-
return color
61+
transforms = color_info[state]
62+
return Color.from_hex(transforms) if isinstance(transforms, str) else _transform(color, transforms)
6263

6364

6465
def svg_format(color: Color) -> str:

qdarktheme/_style_loader.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,17 @@ def _marge_colors(
4848
):
4949
for color_id, color in _mix_theme_colors(custom_colors, theme).items():
5050
try:
51-
parent_key, *child_key = color_id.split(">")
51+
parent_key, *child_keys = color_id.split(">")
5252
color_value = color_values[parent_key]
53-
if len(child_key) == 0:
54-
if isinstance(color_value, dict):
55-
color_value["base"] = color
56-
else:
57-
color_values[parent_key] = color
58-
elif len(child_key) == 1 and isinstance(color_value, dict):
59-
# Check if child_key exists.
60-
color_value[child_key[0]]
61-
color_value[child_key[0]] = color
62-
else:
53+
if len(child_keys) > 1 or (isinstance(color_value, str) and len(child_keys) != 0):
6354
raise KeyError
55+
56+
if isinstance(color_value, str):
57+
color_values[parent_key] = color
58+
else:
59+
child_key = "base" if len(child_keys) == 0 else child_keys[0]
60+
color_value[child_key] # Check if child_key exists.
61+
color_value[child_key] = color
6462
except KeyError:
6563
raise KeyError(f'invalid color id for argument custom_colors: "{color_id}".') from None
6664

0 commit comments

Comments
 (0)