From b81eeacd4f34c2268a3ba62d11f3d1299fdbf241 Mon Sep 17 00:00:00 2001 From: ancongui Date: Wed, 10 Jun 2026 15:32:23 +0200 Subject: [PATCH] fix(ci): satisfy ruff + mypy --strict for the union-safe display_name - registry.py: narrow getattr(...) via isinstance(direct, str) so display_name has no Any return (mypy --strict no-any-return). - tests: use the PEP 604 form (_A | None) instead of typing.Optional (ruff UP). Keeps v26.06.95 green on Lint + Mypy + Test. --- src/pyfly/container/registry.py | 2 +- tests/container/test_registration_display_name.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pyfly/container/registry.py b/src/pyfly/container/registry.py index c9c52ec..518752e 100644 --- a/src/pyfly/container/registry.py +++ b/src/pyfly/container/registry.py @@ -59,7 +59,7 @@ def display_name(self) -> str: return self.name impl = self.impl_type direct = getattr(impl, "__name__", None) - if direct is not None: + if isinstance(direct, str): return direct args = get_args(impl) if args: diff --git a/tests/container/test_registration_display_name.py b/tests/container/test_registration_display_name.py index ab85754..f818240 100644 --- a/tests/container/test_registration_display_name.py +++ b/tests/container/test_registration_display_name.py @@ -30,11 +30,9 @@ def test_display_name_is_union_safe() -> None: assert reg.display_name == "_A | _B" # no AttributeError -def test_display_name_handles_arbitrary_typing_construct() -> None: - from typing import Optional - - # Optional[_A] (== Union[_A, None]) and similar typing constructs must never - # raise; the exact rendering varies by Python version, but it is always a - # usable, non-empty name. - name = Registration(impl_type=Optional[_A]).display_name +def test_display_name_handles_optional_union() -> None: + # ``_A | None`` (the PEP 604 form of Optional) is also a ``types.UnionType`` + # and must never raise; the exact rendering may vary by Python version, but + # it is always a usable, non-empty name. + name = Registration(impl_type=(_A | None)).display_name assert isinstance(name, str) and name