diff --git a/docs/sphinx/source/api/Contributors.md b/docs/sphinx/source/api/Contributors.md index 93c1be9..c2d3f40 100644 --- a/docs/sphinx/source/api/Contributors.md +++ b/docs/sphinx/source/api/Contributors.md @@ -3,7 +3,7 @@ # Modelspec contributors This page list names and Github profiles of contributors to Modelspec, listed in no particular order. -This page is generated periodically, most recently on 2026-03-18. +This page is generated periodically, most recently on 2026-04-29. - Padraig Gleeson ([@pgleeson](https://github.com/pgleeson)) - Manifest Chakalov ([@mqnifestkelvin](https://github.com/mqnifestkelvin)) diff --git a/src/modelspec/base_types.py b/src/modelspec/base_types.py index 7b15e6c..9b31e9c 100644 --- a/src/modelspec/base_types.py +++ b/src/modelspec/base_types.py @@ -665,12 +665,10 @@ def _type_to_str(type_: Any) -> str: A string with a prettier format of the type annotation. """ - # If the type as a __name__ attribute, use that - if hasattr(type_, "__name__"): - return type_.__name__ - - # If its a Generic type - elif get_origin(type_) is not None: + # If it's a Generic type, unwrap it first. + # Note: on Python 3.10+, typing aliases like List[X] have a __name__ attribute + # ("List"), so this must be checked before the __name__ shortcut below. + if get_origin(type_) is not None: if get_origin(type_) is list and len(get_args(type_)) > 0: return Base._type_to_str(get_args(type_)[0]) elif get_origin(type_) is dict and len(get_args(type_)) > 0: @@ -682,6 +680,10 @@ def _type_to_str(type_: Any) -> str: + "]" ) + # If the type has a __name__ attribute, use that + if hasattr(type_, "__name__"): + return type_.__name__ + # Fallback to returning just the string representation. Drop any occurrence of typing return str(type_).replace("typing.", "")