More detailed type annotations in graph visualizations
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- data-visualization
Research direction
Start in htypes.py at get_type_as_string, which currently reduces parameterized types such as dict[str, MySpecialClass] to their base name. Check how the function handles typing.get_args() and verify that the resulting graph type annotation preserves nested type attributes without using fully qualified names. Done means parameterized annotations display their component types while existing simple types remain unchanged.
Written by the indexing model from the issue text.
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, which is currently implemented as:
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
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)
- Dominant language
- Jupyter Notebook
- Stars
- 2.6k
- Forks
- 214
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/hamilton
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug SDK
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
documentation
Difficulty 2/5 1-2 days Newbie friendliness 65/100
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AOSSIE-Org/OrgExplorer#245 · 1 assignee ·
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
gordonwatts/test-wsl2-llm#151 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100