Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/pyfly/container/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 5 additions & 7 deletions tests/container/test_registration_display_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading