From 792d8ea83be3f9ce5e5ce4613803a348640c8c0c Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Mon, 2 Oct 2023 23:49:43 -0500 Subject: [PATCH] Fix `__rich_repr__` type annotation --- msgspec/__init__.pyi | 4 +++- tests/basic_typing_examples.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/msgspec/__init__.pyi b/msgspec/__init__.pyi index 6e4937a0..219fc122 100644 --- a/msgspec/__init__.pyi +++ b/msgspec/__init__.pyi @@ -68,7 +68,9 @@ class Struct: weakref: bool = False, dict: bool = False, ) -> None: ... - def __rich_repr__(self) -> Iterable[Tuple[str, Any]]: ... + def __rich_repr__( + self, + ) -> Iterable[Union[Any, Tuple[Any], Tuple[str, Any], Tuple[str, Any, Any]]]: ... def defstruct( name: str, diff --git a/tests/basic_typing_examples.py b/tests/basic_typing_examples.py index 21cd3fa4..1e686430 100644 --- a/tests/basic_typing_examples.py +++ b/tests/basic_typing_examples.py @@ -311,7 +311,10 @@ class Point(msgspec.Struct): a.x = a.x + b.y repr(a) - for name, val in a.__rich_repr__(): + for item in a.__rich_repr__(): + assert isinstance(item, tuple) + assert len(item) == 2 + name, val = item print(f"{name} = {val}")