-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: Adds vl_convert.pyi
type stub
#185
Conversation
vl-convert-python/pyproject.toml
Outdated
[tool.ruff] | ||
target-version = "py310" | ||
line-length = 88 | ||
indent-width = 4 | ||
exclude = [] | ||
|
||
[tool.ruff.format] | ||
quote-style = "double" | ||
indent-style = "space" | ||
skip-magic-trailing-comma = true | ||
line-ending = "lf" | ||
# https://docs.astral.sh/ruff/formatter/#docstring-formatting | ||
docstring-code-format = true | ||
docstring-code-line-length = 88 | ||
|
||
[tool.ruff.lint] | ||
# https://docs.astral.sh/ruff/preview/ | ||
preview = true | ||
|
||
# https://docs.astral.sh/ruff/settings/#lint_extend-safe-fixes | ||
extend-safe-fixes = [ | ||
# from __future__ import annotations # | ||
# ---------------------------------- # | ||
"UP006", | ||
"UP007", | ||
"UP008", | ||
"TCH", | ||
# unsorted-dunder-all | ||
"RUF022", | ||
# pydocstyle # | ||
# ---------- # | ||
# fits-on-one-line | ||
"D200", | ||
# escape-sequence-in-docstring | ||
"D301", | ||
# ends-in-period | ||
"D400", | ||
] | ||
extend-select = [ | ||
"ANN", | ||
"D", | ||
"D213", | ||
"D400", | ||
"E", | ||
"F", | ||
"FA", | ||
"I001", | ||
"RUF", | ||
"TCH", | ||
"TID", | ||
"UP", | ||
"W", | ||
] | ||
ignore = [ | ||
# indent-with-spaces | ||
"D206", | ||
# multi-line-summary-first-line ((D213) is the opposite of this) | ||
"D212", | ||
# Line too long | ||
"E501", | ||
] | ||
pydocstyle.convention = "numpy" |
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.
I added a subset of https://github.com/vega/altair/blob/main/pyproject.toml to try and keep a consistent style with altair
.
AFAIK these only apply locally, since vl-convert
is using black
.
VegaThemes: TypeAlias = Literal[ | ||
"carbong10", | ||
"carbong100", | ||
"carbong90", | ||
"carbonwhite", | ||
"dark", | ||
"excel", | ||
"fivethirtyeight", | ||
"ggplot2", | ||
"googlecharts", | ||
"latimes", | ||
"powerbi", | ||
"quartz", | ||
"urbaninstitute", | ||
"vox", | ||
] |
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.
Lifted direct from the result of vega/altair#3523
if TYPE_CHECKING: | ||
from typing import Any, Literal, TypeAlias | ||
|
||
FormatLocaleName: TypeAlias = Literal[ |
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.
FormatLocaleName
& TimeFormatLocaleName
I got by following the links that you had in the docs.
The repos seem to have remained pretty constant, so maintaining these (hypothetically) would be on the scale of 2-7 years between changes.
Renderer: TypeAlias = Literal["canvas", "hybrid", "svg"] | ||
FormatLocale: TypeAlias = FormatLocaleName | dict[str, Any] | ||
TimeFormatLocale: TypeAlias = TimeFormatLocaleName | dict[str, Any] | ||
VlSpec: TypeAlias = str | dict[str, Any] |
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.
Though this alias (VlSpec
) could be a placeholder for if you decided to get more specific in the future.
E.g. if you expect a certain level of nesting, this can be updated and propagate to all relevent defs.
The screenshots in vega/altair#3536 show examples of the utility of this
vl-convert-python/vl_convert.pyi
Outdated
Parameters | ||
---------- | ||
vg_spec | ||
Vega JSON specification string or dict | ||
allowed_base_urls | ||
List of allowed base URLs for external data requests. | ||
Default allows any base URL | ||
format_locale | ||
d3-format locale name or dictionary | ||
time_format_locale | ||
d3-time-format locale name or dictionary | ||
|
||
Returns | ||
------- | ||
scenegraph. |
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.
This applies to all docstrings, but I've omited the types since we have them in the signature.
Also most of the descriptions repeat the same information - but I've kept that in
vl-convert-python/vl_convert.pyi
Outdated
renderer: Renderer | None, | ||
) -> str: | ||
""" | ||
Convert a Vega-Lite spec to self-contained HTML document using a particular version of the Vega-Lite JavaScript library. |
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.
I had to disable line-too-long for docs like this.
Splitting it into 2 lines broke multi-line-summary-second-line.
Just thought I'd note this with links to the rules, not proposing any changes
Hi @dangotbanned, thank for working on this. I checked out the branch to review and updated the type signatures for Python 3.8+ compatibility, since vl-convert is a bit more conservative than vega-altair (I try to use current vl-convert with prior versions of Vega-Altair). Take a look and see if that makes sense to you, then I'll merge it |
Thanks @jonmmease! On the EditLooking at the |
@jonmmease I'm thinking this is unrelated to that series of changes? https://github.com/vega/vl-convert/actions/runs/10645388913/job/29511135603?pr=185 Maybe related but I absolutely botched the merge and had to overwrite the whole file with what I had in |
Yes, that CI failure is unrelated. There seems to be an inconsistency in the files that are pulled down from skypack, where they sometimes include a trailing comment. I've been meaning to update the vendoring logic to strip out trailing comments for this reason. I'll restart CI and see if that resolves it for now.
Oh, you're right, these files are only for mypy 🤦♂️ Looks like you're merge reverted to the original form, so that works for me. |
It passes now and looks good to me. Are you ready for it to merge? |
Perfect, yeah I'm happy for you to merge |
Will open a new PR to merge this, related to vega/vl-convert#185
Closes #184
Updated
Tried enabling
pyright
on thetests/
directory and answered my own question onOption
.With that fixed, this is an example in
VSCode
:Suggestion
You could setup
mypy
to run ontests/
to: