Skip to content

Commit

Permalink
Patch for older pythons
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Feb 10, 2024
1 parent e4f42dd commit 73a2c15
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion goodconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 73a2c15

Please sign in to comment.