Skip to content
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 hint for to_json(indent=) should be Optional #3341

Closed
leifwalsh opened this issue Feb 25, 2024 · 1 comment · Fixed by #3342
Closed

type hint for to_json(indent=) should be Optional #3341

leifwalsh opened this issue Feb 25, 2024 · 1 comment · Fixed by #3342
Labels

Comments

@leifwalsh
Copy link

In #3071 and #3073 types were added to some to_json() methods (well, #3071 added the method entirely to TopLevelMixin) that specify indent as an int. In these, indent is only passed along to json.dumps, where it should be possible to pass None or a string as well: https://docs.python.org/3/library/json.html#json.dump

With indent typed as int and defaulting to 2 in the altair API, there is no way to get the compact indent=None serialization in a way that typechecks.

I think the types should be relaxed to str | int | None or something similar.

@binste
Copy link
Contributor

binste commented Feb 25, 2024

Thanks for the detailed report @leifwalsh! Fully agree, I'll change it to Optional[Union[str, int]] for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants