Closed SajidAlamQB closed 3 weeks ago
Hey @astrojuanlu @rashidakanchwala,
I replaced the existing NewType
definitions for TablePreview
, ImagePreview
, PlotlyPreview
, and JSONPreview
with TypedDict
and TypeAlias
. Specifically, TypedDict
was used for TablePreview
to explicitly give its expected structure (e.g., index
, columns
, and data
).
See: https://github.com/kedro-org/kedro-plugins/pull/831
index
, columns
, and data
) when implementing the TablePreview
return value within a preview()
method. This would definitely help users in reducing potential errors when creating custom dataset previews.TypeAlias
is only fully supported from Python 3.10 onwards.NewType
approach or using conditional imports depending on the Python version?Let me know your thoughts.
Example type hint for ImagePreview
:
Auto suggestion for TablePreview
return:
This is amazing! Thanks for the spike.
I had one question. In Juanlu's example he returned a PolarsTable which had a differnt format. He didn't type it out just returned df (which was columns:...) -- does it highlight then too, if this is wrong return type
Good point I just tested it out and unfortunately it doesn't highlight it, TypedDict
seems to provide basic hints, it doesn't enforce the structure strictly.
Great job @SajidAlamQB and good call @rashidakanchwala ! Sad that my original issue wouldn't have been caught by this.
It's still a small improvement in DX, so maybe it would be nice to have.
One issue I found was that TypeAlias is only fully supported from Python 3.10 onwards.
And the small improvement in DX is probably not worth the effort of doing this in a way that it's compatible with Python 3.9...
Thanks for the feedback. Since the type hinting provides some improvement in developer experience but doesn't strictly enforce the structure and has compatibility issues with Python 3.9, we'll close this spike. For now, we'll keep the current approach and revisit in the future.
Description
See here: https://github.com/kedro-org/kedro-viz/issues/1847
By using a type dict or other typing tools, see if the IDE will be able to provide hints that lets users know about the required structure of the preview dictionary (e.g., index, columns, and data keys for TablePreview). Assess how effective the PoC is in helping users keep to the expected preview format and reducing the likelihood of errors due to incorrect return types or structures.
Checklist