From 06cf9f211686eb3a872447a176136fd5429274c8 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sun, 20 Oct 2024 00:10:01 +0100 Subject: [PATCH] marshall.cachew: better exception in case we fail to get type hints from type --- .github/workflows/main.yml | 2 +- src/cachew/marshall/cachew.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cfe4b9c..952b30a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,7 +68,7 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.10' - uses: actions/checkout@v4 with: diff --git a/src/cachew/marshall/cachew.py b/src/cachew/marshall/cachew.py index da11aaf..5971349 100644 --- a/src/cachew/marshall/cachew.py +++ b/src/cachew/marshall/cachew.py @@ -331,7 +331,12 @@ def build_schema(Type) -> Schema: if not (is_dataclass(Type) or is_namedtuple(Type)): raise TypeNotSupported(type_=Type) - hints = get_type_hints(Type) + try: + hints = get_type_hints(Type) + except TypeError as te: + # this can happen for instance on 3.9 if pipe syntax was used for Union types + # would be nice to provide a friendlier error though + raise TypeNotSupported(type_=Type) from te fields = tuple((k, build_schema(t)) for k, t in hints.items()) return SDataclass( type=Type,