Skip to content

Commit

Permalink
Fix Python codegen for enums (#6746)
Browse files Browse the repository at this point in the history
### What

The way enum types were codegen'd in Python was incompatible with python
<=3.9. This PR fixes this.

### 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/6746?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/6746?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/6746)
- [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
abey79 authored Jul 3, 2024
1 parent 67a1705 commit 807fcbd
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 48 deletions.
12 changes: 7 additions & 5 deletions crates/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,13 @@ fn code_for_enum(
}
}

let variants = obj
.fields
.iter()
.map(|v| format!("Literal[{:?}]", v.pascal_case_name().to_lowercase()))
.join(" | ");
let variants = format!(
"Literal[{}]",
obj.fields
.iter()
.map(|v| format!("{:?}", v.pascal_case_name().to_lowercase()))
.join(", ")
);
code.push_unindented(format!("{name}Like = Union[{name}, {variants}]"), 1);
code.push_unindented(
format!(
Expand Down

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.

4 changes: 1 addition & 3 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.

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

2 changes: 1 addition & 1 deletion rerun_py/rerun_sdk/rerun/blueprint/components/view_fit.py

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

10 changes: 1 addition & 9 deletions rerun_py/rerun_sdk/rerun/components/aggregation_policy.py

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

10 changes: 1 addition & 9 deletions rerun_py/rerun_sdk/rerun/components/colormap.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.

12 changes: 1 addition & 11 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.

5 changes: 1 addition & 4 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 807fcbd

Please sign in to comment.