More detailed type annotations in graph visualizations
- Dominant language
- Jupyter Notebook
- Stars
- 2.6k
- Forks
- 213
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
With the current graph visualization, a node with a return type of dict[str,MySpecialClass] will just have "dict" listed as type.
The conversion of the type to string seems to happen in [get_type_as_string](https://github.com/apache/hamilton/blob/eb6a6cac299f5512b94e57b38ce3d0b253cd71e4/hamilton/htypes.py#L111), which is currently implemented as:
```python
def get_type_as_string(type_: Type) -> Optional[str]:
"""Get a string representation of a type.
The logic supports the evolution of the type system between 3.8 and 3.10.
:param type_: Any Type object. Typically the node type found at Node.type.
:return: string representation of the type. An empty string if everything fails.
"""
if _is_annotated_type(type_):
type_string = get_type_as_string(typing.get_args(type_)[0])
elif getattr(type_, "__name__", None):
type_string = type_.__name__
elif typing_inspect.get_origin(type_):
base_type = typing_inspect.get_origin(type_)
type_string = get_type_as_string(base_type)
elif getattr(type_, "__repr__", None):
type_string = type_.__repr__()
else:
type_string = None
return type_string
```
In the above mentioned example this seems to fall into the second case (using__name__), which will discard the type attributes
**Describe the solution you'd like**
Adding
```python
if typing.get_args(type_):
type_string += f"[{', '.join(get_type_as_string(arg) for arg in typing.get_args(type_))}]"
```
before the return seems to fix this issue for my cases.
**Describe alternatives you've considered**
The str() option will return fully qualified names, which might not be desired since it would make text too long. A custom version could be implemented (for example by regex replacing the module names)
Contributor guide
Assessment
This issue has not been assessed yet.