Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/sphinx/source/api/Contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 8 additions & 6 deletions src/modelspec/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.", "")

Expand Down
Loading