-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type hints: Simplify to improve user experiences #3307
Conversation
…and core._Parameter
The latest commit adds back the full list of class names (instead of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this @binste ! I think your changes here makes the docstrings easier to read overall. A few comments:
Fix deduplication of type hints and flatten out nested type hints to one level, i.e. we no longer have Unions within other Unions.
Nice! I noticed that Literals
are now also combined which I think is helpful as well:
However, it seems like they are not combined in the docstring (if this is linked to that we expand SchemaBase
in the docstring, then let's just leave it as is):
For some reason Literal
don't seem to be combined in JupyterLab, but I'm guessing that is a jlab issue and nothing we can improve here:
One question regarding the first VSCode screenshot above, I noticed that we have the type Sequence
repeated several times. Is that something we can change on our end so that it says Sequence[str | bool | float | dict | SchemaBase]
instead?
Somewhat related, I noticed that the docstring says that we accept Sequence[str]
as the shorthand
to e.g. alt.Color
, is this correct? When I try with a list of strings
alt.Chart().mark_point().encode(alt.Color(['test:Q']))
I get this error:
SchemaValidationError: '[{'field': 'test', 'type': 'quantitative'}]' is an invalid value for `color`. Valid values are of type 'object'.
Another thing I noticed is that the signature to the whereas the docstring for I honestly don't think that's something we need to change, just something I noticed when reading through the help popups. |
Thanks for the review Joel! Here some first feedback: LiteralsIn the code, the literals are not combined so seems like VS Code is doing this by itself. I'm somewhat indifferent if its easier to read if they are combined or not. If they are not combined, it gives a certain grouping but it's also more verbose. In any case, combining Literals in the type hints itself would require some larger rewriting of the code generation. If that's ok, I'd prefer to not tackle this in the current PR but happy to work on a follow up issue if you have a strong preference! :) Basically, when I'm flattening the type hints, a literal is already represented as a string, ready for code generation, e.g. SequenceSame story as with literals. |
Sequence[str] for shorthandStruggling to remember the story here. In |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanations! No need to do any large re-write of the code for combining the Literal
s; let's keep it the way it is and leave it up to the IDEs to take care of that.
This looks good from my side of things, but maybe let's leave open a couple of days to see if anyone wants to chime in on the main idea of abbreviating the signatures to use SchemBase
and then the full expansion only in the docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its difficult to get this right. There is a balance between making human-users happy and providing meaningful type-related context. Its great that we try to improve this step by step.
Thank you both! Merging :) |
With this PR I'm trying to address the feedback raised in #3290. It relaxes some of the type hints to improve the readability of the type hints in an IDE such as VS Code and Jupyterlab as well as in the docstrings:
Old:
New:
Union
s within otherUnion
s.Old:
New: