From 73a2c1551996ca8e818e63f444b23de24872a552 Mon Sep 17 00:00:00 2001 From: Peter Baumgartner Date: Sat, 10 Feb 2024 02:12:00 -0700 Subject: [PATCH] Patch for older pythons --- goodconf/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/goodconf/__init__.py b/goodconf/__init__.py index 093eb5e..0425d5c 100644 --- a/goodconf/__init__.py +++ b/goodconf/__init__.py @@ -124,7 +124,13 @@ def type_to_str(tp: Type[Any]) -> str: return f"Optional[{type_to_str(non_none_args[0])}]" if origin: # Generic or special type like Union, Literal, etc. - type_name = origin.__name__ + # Python 3.8 - 3.9 compatibility + if hasattr(origin, '__name__'): + type_name = origin.__name__ + else: + # Attempt to get a readable name for special forms + type_name = repr(origin).replace('typing.', '') + args_str = ", ".join(type_to_str(arg) for arg in args) return f"{type_name}[{args_str}]" return str(tp) # Fallback for any other type