Skip to content

Commit

Permalink
Use literal unions in python enum codegen (#6408)
Browse files Browse the repository at this point in the history
### What

Strings now autocomplete in places where we use enum classes that get
converted from strings.

Follow up to #6407

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6408?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6408?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6408)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
jprochazk committed May 22, 2024
1 parent 364ed5c commit 0270109
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
7 changes: 6 additions & 1 deletion crates/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,12 @@ fn code_for_enum(
}
}

code.push_unindented(format!("{name}Like = Union[{name}, str]"), 1);
let variants = obj
.fields
.iter()
.map(|v| format!("Literal[{:?}]", v.pascal_case_name().to_lowercase()))
.join(" | ");
code.push_unindented(format!("{name}Like = Union[{name}, {variants}]"), 1);
code.push_unindented(
format!(
r#"
Expand Down
2 changes: 1 addition & 1 deletion examples/python/blueprint_stocks/blueprint_stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def style_peak(symbol: str) -> rr.SeriesPoint:
return rr.SeriesPoint(
color=0xFF0000FF,
name=f"{symbol} (peak)",
marker="Up",
marker="up",
)


Expand Down
2 changes: 2 additions & 0 deletions rerun_py/rerun_sdk/rerun/blueprint/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/components/corner2d.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/components/panel_state.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions rerun_py/rerun_sdk/rerun/components/marker_shape.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions rerun_py/tests/test_types/components/enum_test.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0270109

Please sign in to comment.