Skip to content
Closed

fixes #196

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
9 changes: 9 additions & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,24 @@
"ExamplesFlextCliTypes",
"ExamplesFlextCliUtilities",
"_models_parts",
"active_rules",
"api",
"c",
"d",
"discover_repository_root",
"docs_main",
"e",
"h",
"m",
"p",
"r",
"s",
"t",
"td",
"tf",
"tk",
"tm",
"tv",
"u",
"x",
)
Expand Down
47 changes: 45 additions & 2 deletions src/flext_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@
)

if TYPE_CHECKING:
from flext_core import d, e, h, r, x
from flext_infra import docs_main, infra
from flext_tests import (
active_rules,
api,
discover_repository_root,
install_local_packages,
load_infra_report,
split_csv,
td,
tf,
tk,
tm,
tv,
)

from flext_core import core, d, e, h, lazy_attribute, r, x

from . import services
from ._settings import FlextCliSettings, settings
Expand Down Expand Up @@ -85,20 +100,34 @@
"__url__",
"__version__",
"__version_info__",
"active_rules",
"api",
"c",
"cli",
"config",
"d",
"discover_repository_root",
"docs_main",
"e",
"h",
"infra",
"install_local_packages",
"lazy_attribute",
"load_infra_report",
"m",
"main",
"p",
"r",
"s",
"services",
"settings",
"split_csv",
"t",
"td",
"tf",
"tk",
"tm",
"tv",
"u",
"x",
)
Expand Down Expand Up @@ -133,7 +162,21 @@
".services.yaml_model": ("FlextCliYamlModel",),
".typings": ("FlextCliTypes", "t"),
".utilities": ("FlextCliUtilities", "u"),
"flext_core": ("d", "e", "h", "r", "x"),
"flext_core": ("core", "d", "e", "h", "lazy_attribute", "r", "x"),
"flext_infra": ("docs_main", "infra"),
"flext_tests": (
"active_rules",
"api",
"discover_repository_root",
"install_local_packages",
"load_infra_report",
"split_csv",
"td",
"tf",
"tk",
"tm",
"tv",
),
}),
alias_groups=MappingProxyType({}),
sort_keys=False,
Expand Down
53 changes: 27 additions & 26 deletions src/flext_cli/_models/_base/flextclimodelsbase_part_07.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,39 @@
"""Value coerced to type_kind, or default."""
return self.resolve()

def resolve(self) -> t.Cli.TypedExtractValue:

Check failure on line 62 in src/flext_cli/_models/_base/flextclimodelsbase_part_07.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=flext-sh_flext-cli&issues=AaDVmAMb5SEif2YqrEE6&open=AaDVmAMb5SEif2YqrEE6&pullRequest=196
"""Type-safe accessor (bypasses pyrefly computed_field limitation)."""
default_value = self._default_for_kind()
if self.value is None:
return default_value
resolved_value: t.Cli.TypedExtractValue = default_value

Check warning on line 67 in src/flext_cli/_models/_base/flextclimodelsbase_part_07.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this assignment to local variable 'resolved_value'; the value is never used.

See more on https://sonarcloud.io/project/issues?id=flext-sh_flext-cli&issues=AaDVmAMb5SEif2YqrEE5&open=AaDVmAMb5SEif2YqrEE5&pullRequest=196
match self.type_kind:
case c.Cli.TypeKind.STR:
resolved_str = str(self.value).strip() if self.value else ""
resolved_value = resolved_str or (
self.default if isinstance(self.default, str) else ""
)
case c.Cli.TypeKind.BOOL:
resolved_value = bool(self.value)
case c.Cli.TypeKind.DICT:
source_mapping = (
self.value
if isinstance(self.value, Mapping)
else self.default
if isinstance(self.default, Mapping)
else None
)
resolved_value = (
{
k: t.Cli.JSON_VALUE_ADAPTER.validate_python(vv)
for k, vv in source_mapping.items()
}
if source_mapping is not None
else _EMPTY_JSON_MAPPING
)
case _:
pass
# If-chains, not `match`: the lazy facade types `self.type_kind` as
# Unknown to pyright, which cannot prove a match exhaustive even
# though the arms cover every TypeKind member (same idiom as
# `_default_for_kind` below).
if self.type_kind == c.Cli.TypeKind.STR:
resolved_str = str(self.value).strip() if self.value else ""
resolved_value = resolved_str or (
self.default if isinstance(self.default, str) else ""
)
elif self.type_kind == c.Cli.TypeKind.BOOL:
resolved_value = bool(self.value)
else:
source_mapping = (
self.value
if isinstance(self.value, Mapping)
else self.default
if isinstance(self.default, Mapping)
else None
)
resolved_value = (
{
k: t.Cli.JSON_VALUE_ADAPTER.validate_python(vv)
for k, vv in source_mapping.items()
}
if source_mapping is not None
else _EMPTY_JSON_MAPPING
)
return resolved_value

def _default_for_kind(self) -> t.Cli.TypedExtractValue:
Expand Down
50 changes: 46 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@
from flext_core.lazy import build_lazy_import_map, install_lazy_exports

if TYPE_CHECKING:
from flext_tests import api, td, tf, tk, tm, tv
from flext_infra import docs_main, infra
from flext_tests import (
active_rules,
api,
config,
discover_repository_root,
install_local_packages,
load_infra_report,
settings,
split_csv,
td,
tf,
tk,
tm,
tv,
)

from flext_core import d, e, h, r, x
from flext_cli import cli, main
from flext_core import core, d, e, h, lazy_attribute, r, x

from . import unit
from .base import TestsFlextCliServiceBase, TestsFlextCliServiceBase as s
Expand All @@ -31,15 +47,24 @@
"TestsFlextCliSettings",
"TestsFlextCliTypes",
"TestsFlextCliUtilities",
"active_rules",
"api",
"c",
"d",
"discover_repository_root",
"docs_main",
"e",
"h",
"infra",
"install_local_packages",
"lazy_attribute",
"load_infra_report",
"m",
"p",
"r",
"s",
"settings",
"split_csv",
"t",
"td",
"tf",
Expand All @@ -62,8 +87,25 @@
".typings": ("TestsFlextCliTypes", "t"),
".unit": ("unit",),
".utilities": ("TestsFlextCliUtilities", "u"),
"flext_core": ("d", "e", "h", "r", "x"),
"flext_tests": ("api", "td", "tf", "tk", "tm", "tv"),
"flext_cli": ("cli", "main"),
"flext_core": ("core", "d", "e", "h", "lazy_attribute", "r", "x"),
"flext_infra": ("docs_main", "infra"),
"flext_tests": (
"active_rules",
"api",
"config",
"discover_repository_root",
"install_local_packages",
"load_infra_report",
"settings",
"split_csv",
"td",
"tf",
"tk",
"tm",
"tv",
"x",
),
}),
alias_groups=MappingProxyType({}),
sort_keys=False,
Expand Down
Loading